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

📄 vanetrbc_rxdatadb.cc

📁 基于NS-2的车辆Ad Hoc网络(VANET)的一个应用层协议框架
💻 CC
字号:
/* ------------------------------------------------------------------- * Vehicular Ad Hoc Networks: Regular Broadcasting of messages. * Skeleton for VANET-protocols. This should be considered as an * example to create other VANET protocols! * Apart from channel load, the "protocol" as it is now does not do * anything useful. * * Dan Jungels (daniel.jungels@epfl.ch) * LCA - EPFL * * * ReceiveData-database * Originally written for ns2.29 * * 2005-12-15: release of first version (dj) * 2005-12-23: update and cleanup, public release (dj) * ------------------------------------------------------------------- */#include "vanetrbc_rxdatadb.h"// ReceiveData database: stores some information about packets of recently// heard nodes.// constructorvanetrbc_rxdatadb::vanetrbc_rxdatadb() { }voidvanetrbc_rxdatadb::print(Trace* out) {    sprintf(out->pt_->buffer(), "\theard ID\t at time\t at xPos\t at yPos");    out->pt_->dump();        for (rxdatadb_t::iterator it = rxddb_.begin(); it != rxddb_.end(); it++) {                u_int32_t id = (*it).first;     // heard id        rxData_t rxd = (*it).second;    // timestamp, etc        double tstamp = rxd.tStamp;        double xpos = rxd.xPos;        double ypos = rxd.yPos;                // dump it in a human readable form. you may change this to a more        // awk-friendly style (e.g., "RXDATA " and then a space separated list)        sprintf(out->pt_->buffer(), "\t%d\t\t%f\t%f\t%f",                                                    id, tstamp, xpos, ypos);        out->pt_->dump();            }}voidvanetrbc_rxdatadb::clear() {    rxddb_.clear();}voidvanetrbc_rxdatadb::rm_entry(u_int32_t id) {    rxddb_.erase(id);}voidvanetrbc_rxdatadb::add_entry(u_int32_t id, double tstamp,                                                double xpos, double ypos) {    rxData_t rxd;    rxd.tStamp = tstamp;    rxd.xPos = xpos;    rxd.yPos = ypos;    // if there is already an entry for "id", it is replaced by the new one    rxddb_[id] = rxd;}doublevanetrbc_rxdatadb::lookup(u_int32_t id) {    rxdatadb_t::iterator it = rxddb_.find(id);    if (it == rxddb_.end())        return -1.0;    // nothing found    else {        rxData_t rxd = (*it).second;        double tstamp = rxd.tStamp;        return tstamp;  // return the timestamp (for example)    }}// ! you may extend this by some functions to fit your needs (for example,// to return the number of nodes heard during the last xx seconds, etc).

⌨️ 快捷键说明

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