⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rajaraman.cc

📁 clustering for ns-2 simulation
💻 CC
字号:
/** * Copyright (c) 2006 Michele Mastrogiovanni. * *   Licensed under the Apache License, Version 2.0 (the "License"); *   you may not use this file except in compliance with the License. *   You may obtain a copy of the License at * *       http://www.apache.org/licenses/LICENSE-2.0 * *   Unless required by applicable law or agreed to in writing, software *   distributed under the License is distributed on an "AS IS" BASIS, *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *   See the License for the specific language governing permissions and *   limitations under the License. * */// Ricorda sempre di rendere concordi l'assegnazione del clusterHead e la cover:// un nodo clusterHead e'anche cevered.////////////////// NS Headers //////////////////#include "rajaraman.h"#include "random.h"#include "gridkeeper.h"#include "Separator.h"#include <algorithm>///////////////////////////////////// Parte di dichiarazione comune /////////////////////////////////////int hdr_rajaraman::offset_;int RAJARAMAN_Agent::_DEBUG_;	int RAJARAMAN_Agent::rounded_span;int RAJARAMAN_Agent::fraction;double RAJARAMAN_Agent::max_delay;int RAJARAMAN_Agent::max_timeout_message;double RAJARAMAN_Agent::jitter_timeout_message;double RAJARAMAN_Agent::timeout_message;int RAJARAMAN_Agent::b_param;static class RajaramanClass : public TclClass {public:    RajaramanClass() : TclClass("Agent/RAJARAMAN") {}    TclObject* create(int , const char*const* ) {        return(new RAJARAMAN_Agent());    }} class_rajaraman;static class RajaramanHeaderClass : public PacketHeaderClass {public:	RajaramanHeaderClass() : PacketHeaderClass("PacketHeader/RAJARAMAN",										  sizeof(hdr_rajaraman)) {		bind_offset(&hdr_rajaraman::offset_);	}} class_rajaramanhdr;void RajaramanTimer::clearAll(){	message_timeouts.clear();}// Definizione del timer.voidRajaramanTimer::handle(Event * e) {	//	// Timeout MESSAGE.	//    for (TimeoutMap::iterator i = message_timeouts.begin(); i != message_timeouts.end(); i++) {        if (i->second.timeout == e) {            i->second.num--;            if (i->second.num <= 0) {                agent->lastTimeout(i->first, RAJARAMAN_Agent::max_timeout_message - i->second.num);            }            else {                Scheduler::instance().schedule(this, e,                     RAJARAMAN_Agent::timeout_message + Random::uniform(RAJARAMAN_Agent::jitter_timeout_message));                agent->timeout(i->first, RAJARAMAN_Agent::max_timeout_message - i->second.num);            }        }    }	//	// Timeout TERMINATION.	//    for (TimeoutMap::iterator i = termination_timeouts.begin(); i != termination_timeouts.end(); i++) {        if (i->second.timeout == e) {            i->second.num--;            if (i->second.num <= 0) {                agent->lastTimeoutTermination(i->first, RAJARAMAN_Agent::max_timeout_message - i->second.num);            }            else {                Scheduler::instance().schedule(this, e,                     RAJARAMAN_Agent::timeout_message + Random::uniform(RAJARAMAN_Agent::jitter_timeout_message));                agent->timeoutTermination(i->first, RAJARAMAN_Agent::max_timeout_message - i->second.num);            }        }    }}//// Lancia un timeout verso una lista di vicini.//voidRajaramanTimer::launchMessageTimeout(NodeList & neighbors){    for (NodeList::iterator i = neighbors.begin(); i != neighbors.end(); i++) {		//        // Definisce i Timeout di tipo MESSAGE		//        struct Timeout h;        h.timeout = new Event();        h.num = RAJARAMAN_Agent::max_timeout_message;        message_timeouts[*i] = h;        Scheduler::instance().schedule(this, h.timeout, RAJARAMAN_Agent::timeout_message + Random::uniform(RAJARAMAN_Agent::jitter_timeout_message));    }    }//// Lancia un timeout verso una lista di vicini.//voidRajaramanTimer::launchTerminationTimeout(NodeList & neighbors){    for (NodeList::iterator i = neighbors.begin(); i != neighbors.end(); i++) {		//        // Definisce i Timeout di tipo MESSAGE		//        struct Timeout h;        h.timeout = new Event();        h.num = RAJARAMAN_Agent::max_timeout_message;        termination_timeouts[*i] = h;        Scheduler::instance().schedule(this, h.timeout, RAJARAMAN_Agent::timeout_message + Random::uniform(RAJARAMAN_Agent::jitter_timeout_message));    }    }//// Elimina un timeout.//voidRajaramanTimer::receivedMessage(NodeAddress from){    TimeoutMap::iterator i;    for (i = message_timeouts.begin(); i != message_timeouts.end(); i++) {        if ((i->first) == from) {            Scheduler::instance().cancel((i->second).timeout);            break;        }    }    if (i != message_timeouts.end())        message_timeouts.erase(i);}//// Elimina un timeout.//voidRajaramanTimer::receivedTermination(NodeAddress from){    TimeoutMap::iterator i;    for (i = termination_timeouts.begin(); i != termination_timeouts.end(); i++) {        if ((i->first) == from) {            Scheduler::instance().cancel((i->second).timeout);            break;        }    }    if (i != termination_timeouts.end())        termination_timeouts.erase(i);}//// Costruttore dell'agente.//RAJARAMAN_Agent::RAJARAMAN_Agent() : ClusteringModule(PT_RAJARAMAN), currentTime(0, RAJARAMAN_PHASE_SPAN_1, RAJARAMAN_PHASE_DECISION_2), ended(false){	timer = new RajaramanTimer(this);		bind_bool("debug", &_DEBUG_);	bind_bool("rounded-span", &rounded_span);	bind_bool("fraction", &fraction);		bind("b-param", &b_param);		bind("max-delay", &max_delay);	bind("max-timeout-message", &max_timeout_message);	bind("jitter-timeout-message", &jitter_timeout_message);	bind("timeout-message", &timeout_message);}//// Determina il rounded_span in base al parametro B.// Si assume che il valore passato come SPAN sia // maggiore o uguale a 0.// Il rounded span di 0 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -