Commit aacc7327 authored by Laurent Velez's avatar Laurent Velez
Browse files

Initial commit

parents
/CSE_Network_V3.6.3.exe
[General]
last-configname=LargeNetwork
last-runnumber=0
[RunModeProfiles]
fast-max-animation-speed=nan
fast-max-playback-speed=1e+06
fast-min-animation-speed=nan
fast-min-playback-speed=1
fast-playback-speed=1000
run-max-animation-speed=nan
run-max-playback-speed=100
run-min-animation-speed=nan
run-min-playback-speed=0.01
run-playback-speed=1.5488166189124815
#include "AE.h"
#include "discoveryMessage_m.h"
#include "utils.h"
#include "types.h"
#include <iostream>
int AE::numInitStages() const {
return 2;
}
void AE::registration() {
this->queryIndex = 0;
this->warmup = par("warmup");
// get the id of the AE
URI = getId(); // this is the omnet id which is given when creating the module in the NED file (sequential numbering )
// assigning randomly the data
data = uniform(0, 100);
int ran_number = std::rand() % 100;
EV << "Random Number" << ran_number << "\n";
// maxhop set to 10
maxHop = par("maxHops");
resource_pool_size = par("resource_pool_size");
this->feature_type = std::to_string(std::rand() % resource_pool_size).c_str();
// send an AE message with op_code Registration
sendAEMessage(REGISTRATION);
//
// if (getIndex() % 5 == 1) {
// sendAEMessage(CANCELLATION);
// }
}
void AE::sendQuery() {
// getIndex is an omnet function that select in a vector of AE (in this case ) the index in the vector table.
if ((std::rand() % 5) == 1) {
// send the AE message with op_code QUERY
// EV << "AE of URI 28 is Searching for waterValve" << "\n";
sendAEMessage(QUERY);
}
if ((std::rand() % 15) == 1) {
// send the AE message with op_code QUERY
// EV << "AE of URI 28 is Searching for waterValve" << "\n";
sendAEMessage(CANCELLATION);
}
}
void AE::initialize(int stage) {
number_of_replies = 0;
successRate = registerSignal("number_replies");
switch (stage) {
case InitStage::INIT_REGISTRATION:
registration();
break;
case InitStage::INIT_QUERY:
sendQuery();
break;
default: {
EV_FATAL << "Unknown initialization phase!\n";
break;
}
}
} // end of initialize
void AE::sendAEMessage(int op_code) {
// this function we set the fields of an AEMessage with respect to op_code
switch (op_code) {
case CANCELLATION: {
AEMessage *regMsg = new AEMessage("C");
// set the message fields
regMsg->setURI(URI);
regMsg->setData(data);
regMsg->setOp_code(CANCELLATION);
regMsg->setFeature_type(feature_type.c_str());
//send to the output gate of the AE $o as output and 0 is the number
sendDelayed(regMsg, simTime() + this->warmup + (std::rand()%5), "cse$o", 0);
break;
}
case REGISTRATION: {
AEMessage *regMsg = new AEMessage("Rg");
// set the message fields
regMsg->setURI(URI);
regMsg->setFeature_type(feature_type.c_str());
regMsg->setData(data);
regMsg->setOp_code(REGISTRATION);
SimTime t;
t.setRaw(1);
//send to the output gate of the AE $o as output and 0 is the number
sendDelayed(regMsg, simTime() + exponential(t), "cse$o", 0);
break;
} // end of REGISTRATION case
case QUERY: {
AEMessage *queryMsg = new AEMessage("Q");
queryMsg->setURI(URI);
queryMsg->setQueryID(queryIndex++);
queryMsg->setFeature_type(std::to_string(std::rand() % resource_pool_size).c_str());
queryMsg->setOp_code(QUERY);
queryMsg->setMaxHop(maxHop);
sendDelayed(queryMsg, simTime() + this->warmup, "cse$o", 0);
break;
} // end of QUERY case
default:
break;
} // end of switch
} // end of function sendAEMessage
void AE::handleMessage(cMessage *msg) {
static int NumOfReplies = 0;
//AE will receive the response
//AEMessage *responseMsg = check_and_cast<AEMessage *>(msg);
discoveryMessage *responseMsg = check_and_cast<discoveryMessage*>(msg);
EV << "AE receives a response" << "\n";
int number_of_response=0;
number_of_response++;
if (responseMsg->getReturnCode() == ResultCode::SUCCESS) {
number_of_successfulResponse= 0;
number_of_successfulResponse++;
EV << "Resource of type " << responseMsg->getFeature_type()
<< " found in " << responseMsg->getURI_init() << "\n";
}
if (responseMsg->getReturnCode() == ResultCode::NOT_FOUND) {
EV << "Resource of type " << responseMsg->getFeature_type()
<< " not found in" << responseMsg->getURI_init() << "\n";
}
number_of_replies++;
emit(successRate, number_of_replies);
delete responseMsg;
}
#ifndef AE_H_
#define AE_H_
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include "AEMessage_m.h"
#include "utils.h"
using namespace omnetpp;
//using namespace std;
enum InitStage {
INIT_REGISTRATION = 0,
INIT_QUERY = 1
};
class AE : public cSimpleModule // one of the module type in omnet
{
protected:
// by default in omnet methods
virtual void initialize(int stage) override;
virtual void handleMessage(cMessage *msg) override;
// application specific
void sendAEMessage(int op_code);
void registration();
void sendQuery();
virtual int numInitStages() const;
private:
int warmup;
int queryIndex;
int URI;
int data;
int maxHop;
int ran_number;
std::string feature_type;
std::vector<std::string> feature_types {
"thermometer","airStation","ATM","smartLock", "waterValve"
};
int resource_pool_size;
int number_of_replies;
int number_of_successfulResponse;
protected:
simsignal_t successRate;
};
Define_Module(AE);
#endif /* AE_H_ */
message AEMessage
{
int queryID;
int URI; // this is the unique identifer of the AE, sending the message
string feature_type; // this is the feature type of the resource we are looking for; in this version of protocol
// we can just query one feature type per QUERY
int data; // this is the value concerning the resource we are looking for; Actually used in REGISTRATION.
// TO DO it will be used in UPDATE, PUT, GET, REPLY.
int op_code; // this can be
// REGISTRATION (when AE register to CSE), value =0
// UPDATE (when AE update every x minutes the CSE about the update in its value in local Database); value =1
// CANCELLATION (when AE wants to cancel the Resource inside CSE local Database) value =2
// QUERY (when AE wants to ask for resource), value =3
// PUT (CSE to AE: CSE gives some directive to the corresponding AE) value =4
// GET (CSE to AE: CSE ask some value from the corresponding AE) value =5
// REPLY (AE to CSE: AE reply to the CSE with a value normally in data) value =6
// RESPONSE (AE to CSE: AE reply to the CSE with a value normally in data) value =7
// NOTIFY between CSE to notify modifcations in route tables value =8
int maxHop; // used for a discovery query. Number of hops for the search
}
//
// Generated file, do not edit! Created by nedtool 5.6 from AEMessage.msg.
//
// Disable warnings about unused variables, empty switch stmts, etc:
#ifdef _MSC_VER
# pragma warning(disable:4101)
# pragma warning(disable:4065)
#endif
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wshadow"
# pragma clang diagnostic ignored "-Wconversion"
# pragma clang diagnostic ignored "-Wunused-parameter"
# pragma clang diagnostic ignored "-Wc++98-compat"
# pragma clang diagnostic ignored "-Wunreachable-code-break"
# pragma clang diagnostic ignored "-Wold-style-cast"
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wconversion"
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wold-style-cast"
# pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
# pragma GCC diagnostic ignored "-Wfloat-conversion"
#endif
#include <iostream>
#include <sstream>
#include "AEMessage_m.h"
namespace omnetpp {
// Template pack/unpack rules. They are declared *after* a1l type-specific pack functions for multiple reasons.
// They are in the omnetpp namespace, to allow them to be found by argument-dependent lookup via the cCommBuffer argument
// Packing/unpacking an std::vector
template<typename T, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::vector<T,A>& v)
{
int n = v.size();
doParsimPacking(buffer, n);
for (int i = 0; i < n; i++)
doParsimPacking(buffer, v[i]);
}
template<typename T, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::vector<T,A>& v)
{
int n;
doParsimUnpacking(buffer, n);
v.resize(n);
for (int i = 0; i < n; i++)
doParsimUnpacking(buffer, v[i]);
}
// Packing/unpacking an std::list
template<typename T, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::list<T,A>& l)
{
doParsimPacking(buffer, (int)l.size());
for (typename std::list<T,A>::const_iterator it = l.begin(); it != l.end(); ++it)
doParsimPacking(buffer, (T&)*it);
}
template<typename T, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::list<T,A>& l)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
l.push_back(T());
doParsimUnpacking(buffer, l.back());
}
}
// Packing/unpacking an std::set
template<typename T, typename Tr, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::set<T,Tr,A>& s)
{
doParsimPacking(buffer, (int)s.size());
for (typename std::set<T,Tr,A>::const_iterator it = s.begin(); it != s.end(); ++it)
doParsimPacking(buffer, *it);
}
template<typename T, typename Tr, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::set<T,Tr,A>& s)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
T x;
doParsimUnpacking(buffer, x);
s.insert(x);
}
}
// Packing/unpacking an std::map
template<typename K, typename V, typename Tr, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::map<K,V,Tr,A>& m)
{
doParsimPacking(buffer, (int)m.size());
for (typename std::map<K,V,Tr,A>::const_iterator it = m.begin(); it != m.end(); ++it) {
doParsimPacking(buffer, it->first);
doParsimPacking(buffer, it->second);
}
}
template<typename K, typename V, typename Tr, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::map<K,V,Tr,A>& m)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
K k; V v;
doParsimUnpacking(buffer, k);
doParsimUnpacking(buffer, v);
m[k] = v;
}
}
// Default pack/unpack function for arrays
template<typename T>
void doParsimArrayPacking(omnetpp::cCommBuffer *b, const T *t, int n)
{
for (int i = 0; i < n; i++)
doParsimPacking(b, t[i]);
}
template<typename T>
void doParsimArrayUnpacking(omnetpp::cCommBuffer *b, T *t, int n)
{
for (int i = 0; i < n; i++)
doParsimUnpacking(b, t[i]);
}
// Default rule to prevent compiler from choosing base class' doParsimPacking() function
template<typename T>
void doParsimPacking(omnetpp::cCommBuffer *, const T& t)
{
throw omnetpp::cRuntimeError("Parsim error: No doParsimPacking() function for type %s", omnetpp::opp_typename(typeid(t)));
}
template<typename T>
void doParsimUnpacking(omnetpp::cCommBuffer *, T& t)
{
throw omnetpp::cRuntimeError("Parsim error: No doParsimUnpacking() function for type %s", omnetpp::opp_typename(typeid(t)));
}
} // namespace omnetpp
// forward
template<typename T, typename A>
std::ostream& operator<<(std::ostream& out, const std::vector<T,A>& vec);
// Template rule which fires if a struct or class doesn't have operator<<
template<typename T>
inline std::ostream& operator<<(std::ostream& out,const T&) {return out;}
// operator<< for std::vector<T>
template<typename T, typename A>
inline std::ostream& operator<<(std::ostream& out, const std::vector<T,A>& vec)
{
out.put('{');
for(typename std::vector<T,A>::const_iterator it = vec.begin(); it != vec.end(); ++it)
{
if (it != vec.begin()) {
out.put(','); out.put(' ');
}
out << *it;
}
out.put('}');
char buf[32];
sprintf(buf, " (size=%u)", (unsigned int)vec.size());
out.write(buf, strlen(buf));
return out;
}
Register_Class(AEMessage)
AEMessage::AEMessage(const char *name, short kind) : ::omnetpp::cMessage(name,kind)
{
this->queryID = 0;
this->URI = 0;
this->data = 0;
this->op_code = 0;
this->maxHop = 0;
}
AEMessage::AEMessage(const AEMessage& other) : ::omnetpp::cMessage(other)
{
copy(other);
}
AEMessage::~AEMessage()
{
}
AEMessage& AEMessage::operator=(const AEMessage& other)
{
if (this==&other) return *this;
::omnetpp::cMessage::operator=(other);
copy(other);
return *this;
}
void AEMessage::copy(const AEMessage& other)
{
this->queryID = other.queryID;
this->URI = other.URI;
this->feature_type = other.feature_type;
this->data = other.data;
this->op_code = other.op_code;
this->maxHop = other.maxHop;
}
void AEMessage::parsimPack(omnetpp::cCommBuffer *b) const
{
::omnetpp::cMessage::parsimPack(b);
doParsimPacking(b,this->queryID);
doParsimPacking(b,this->URI);
doParsimPacking(b,this->feature_type);
doParsimPacking(b,this->data);
doParsimPacking(b,this->op_code);
doParsimPacking(b,this->maxHop);
}
void AEMessage::parsimUnpack(omnetpp::cCommBuffer *b)
{
::omnetpp::cMessage::parsimUnpack(b);
doParsimUnpacking(b,this->queryID);
doParsimUnpacking(b,this->URI);
doParsimUnpacking(b,this->feature_type);
doParsimUnpacking(b,this->data);
doParsimUnpacking(b,this->op_code);
doParsimUnpacking(b,this->maxHop);
}
int AEMessage::getQueryID() const
{
return this->queryID;
}
void AEMessage::setQueryID(int queryID)
{
this->queryID = queryID;
}
int AEMessage::getURI() const
{
return this->URI;
}
void AEMessage::setURI(int URI)
{
this->URI = URI;
}
const char * AEMessage::getFeature_type() const
{
return this->feature_type.c_str();
}
void AEMessage::setFeature_type(const char * feature_type)
{
this->feature_type = feature_type;
}
int AEMessage::getData() const
{
return this->data;
}
void AEMessage::setData(int data)
{
this->data = data;
}
int AEMessage::getOp_code() const
{
return this->op_code;
}
void AEMessage::setOp_code(int op_code)
{
this->op_code = op_code;
}
int AEMessage::getMaxHop() const
{
return this->maxHop;
}
void AEMessage::setMaxHop(int maxHop)
{
this->maxHop = maxHop;
}
class AEMessageDescriptor : public omnetpp::cClassDescriptor
{
private:
mutable const char **propertynames;
public:
AEMessageDescriptor();
virtual ~AEMessageDescriptor();
virtual bool doesSupport(omnetpp::cObject *obj) const override;
virtual const char **getPropertyNames() const override;
virtual const char *getProperty(const char *propertyname) const override;
virtual int getFieldCount() const override;
virtual const char *getFieldName(int field) const override;
virtual int findField(const char *fieldName) const override;
virtual unsigned int getFieldTypeFlags(int field) const override;
virtual const char *getFieldTypeString(int field) const override;
virtual const char **getFieldPropertyNames(int field) const override;
virtual const char *getFieldProperty(int field, const char *propertyname) const override;
virtual int getFieldArraySize(void *object, int field) const override;
virtual const char *getFieldDynamicTypeString(void *object, int field, int i) const override;
virtual std::string getFieldValueAsString(void *object, int field, int i) const override;
virtual bool setFieldValueAsString(void *object, int field, int i, const char *value) const override;
virtual const char *getFieldStructName(int field) const override;
virtual void *getFieldStructValuePointer(void *object, int field, int i) const override;
};
Register_ClassDescriptor(AEMessageDescriptor)
AEMessageDescriptor::AEMessageDescriptor() : omnetpp::cClassDescriptor("AEMessage", "omnetpp::cMessage")
{
propertynames = nullptr;
}
AEMessageDescriptor::~AEMessageDescriptor()
{
delete[] propertynames;
}
bool AEMessageDescriptor::doesSupport(omnetpp::cObject *obj) const
{
return dynamic_cast<AEMessage *>(obj)!=nullptr;
}
const char **AEMessageDescriptor::getPropertyNames() const
{
if (!propertynames) {
static const char *names[] = { nullptr };
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
const char **basenames = basedesc ? basedesc->getPropertyNames() : nullptr;
propertynames = mergeLists(basenames, names);
}
return propertynames;
}
const char *AEMessageDescriptor::getProperty(const char *propertyname) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? basedesc->getProperty(propertyname) : nullptr;
}
int AEMessageDescriptor::getFieldCount() const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? 6+basedesc->getFieldCount() : 6;
}
unsigned int AEMessageDescriptor::getFieldTypeFlags(int field) const