Closed OverwatchGirl closed 3 years ago
Remove the first two lines from your TokenB.hpp, which are unnecessary with #pragma once
.
#ifndef __VANETZA_TOKENB_H
#define __VANETZA_TOKENB_H
I don't recommend including any OMNeT++ headers in Vanetza as it requires you to add OMNeT++ as a dependency to Vanetza then. Please use vanetza::Clock
for time related code in Vanetza. You can see that to many classes in Vanetza a Runtime
object is passed at construction. Such a Runtime
object provides the current time.
Hello again @riebl !
I removed them but i still get the same error.
Oh, and no #pragma once
in your source file. These include guards are only necessary for header files.
I removed that too! and i still get the same error ! :'(
I have modified your code as little as possible to compile it without errors:
TokenB.hpp
#pragma once
#include <vanetza/dcc/data_request.hpp>
#include <vanetza/dcc/interface.hpp>
#include <vanetza/dcc/transmission.hpp>
#include <vanetza/net/chunk_packet.hpp>
#include <boost/optional/optional.hpp>
#include <vanetza/dcc/profile.hpp>
#include <vanetza/access/access_category.hpp>
#include <vanetza/common/clock.hpp>
#include <list>
#include <memory>
#include <map>
#include <atomic>
#include <chrono>
#include <omnetpp/simtime.h>
namespace vanetza
{
namespace dcc
{
class TokenBucket {
private :
double CIR;
long CBS;
//initialisation du bucket to plein burst
long Tc = 8*CBS; // token bucket for committed burst
omnetpp::SimTime lastUpdateTime ;
int numRcvd;
int numRed;
public :
TokenBucket();
TokenBucket(double cir, long cbs);
int handleMessage(const DataRequest& request, std::unique_ptr<ChunkPacket> packet);
int meterPacket(const DataRequest& request, std::unique_ptr<ChunkPacket> packet);
};
}//dcc
}//vanetza
TokenB.cpp
#include <vanetza/common/hook.hpp>
#include <vanetza/dcc/data_request.hpp>
#include <vanetza/dcc/interface.hpp>
#include <vanetza/dcc/transmission.hpp>
#include <vanetza/net/chunk_packet.hpp>
#include <boost/optional/optional.hpp>
#include <vanetza/dcc/profile.hpp>
#include <vanetza/access/access_category.hpp>
#include <vanetza/common/clock.hpp>
#include <list>
#include <memory>
#include <map>
#include <atomic>
#include <chrono>
#include <omnetpp/csimulation.h>
#include <vanetza/dcc/TokenB.hpp>
using namespace omnetpp;
namespace vanetza
{
namespace dcc
{
enum Color
{
RED, GREEN
};
int TokenBucket::handleMessage(const DataRequest& request, std::unique_ptr<ChunkPacket> packet)
{
numRcvd++;
int color = meterPacket(request, std::move(packet));
if (color == GREEN) {
return 1;
}
else {
numRed++;
return 0;
}
}
int TokenBucket::meterPacket(const DataRequest& request, std::unique_ptr<ChunkPacket> packet)
{
// update token buckets
SimTime currentTime = simTime();
long numTokens = (long)(SIMTIME_DBL(currentTime - lastUpdateTime) * CIR);
lastUpdateTime = currentTime;
if (Tc + numTokens <= CBS)
Tc += numTokens;
else
Tc = CBS;
// update meter state
int oldColor = -1;
int newColor;
int packetSizeInBits = packet->size()*8; //.size() returns size in bytes
if (oldColor <= GREEN && Tc - packetSizeInBits >= 0) {
Tc -= packetSizeInBits;
newColor = GREEN;
}
else
newColor = RED;
//setColor(packet, newColor);
return newColor;
}
}//dcc
}//vanetza
As I said before, you need to add OMNeT++ as a dependency to Vanetza then. Otherwise, the #include <omnetpp/...>
fails.
Hello !
I add it to the artery/extern/vanetza/CMakeLists.txt ?? i don't know how to add dependencies to Vanetza, can you please show me how to do it ?
Thank you.
If you really want to keep the OMNeT++ headers in your TokenBucket
code, then I suggest moving your files to src/artery/networking/TokenBucket.{h,cc}. The Artery project already depends on both OMNeT++ and Vanetza, so you don't need to set these dependencies up yourself.
Actually , i tried to use Runtime
object, but it caused me other errors.
If i add it to networking
, will still be able to call it from vanetza/dcc/flow_control.cpp
No, but you could modify src/artery/networking/DccEntityBase.cc to use TokenBucket
instead of FlowControl
.
No further reply from the ticket creator, closing.
Hello @riebl !!
Here's my TokenB.hpp code :
and here's my TokenB.cpp code :
the error message that i am getting when compiling these files is :
( "Aucun fichier ou dossier de ce type" means : no such file or directory )
Thank you !