Loading src/.gitignore 0 → 100644 +1 −0 Original line number Diff line number Diff line /CSE_Network_V3.6.3.exe src/.qtenvrc 0 → 100644 +15 −0 Original line number Diff line number Diff line [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 src/AE.cpp 0 → 100644 +139 −0 Original line number Diff line number Diff line #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; } src/AE.h 0 → 100644 +59 −0 Original line number Diff line number Diff line #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_ */ src/AEMessage.msg 0 → 100644 +23 −0 Original line number Diff line number Diff line 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 } Loading
src/.gitignore 0 → 100644 +1 −0 Original line number Diff line number Diff line /CSE_Network_V3.6.3.exe
src/.qtenvrc 0 → 100644 +15 −0 Original line number Diff line number Diff line [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
src/AE.cpp 0 → 100644 +139 −0 Original line number Diff line number Diff line #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; }
src/AE.h 0 → 100644 +59 −0 Original line number Diff line number Diff line #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_ */
src/AEMessage.msg 0 → 100644 +23 −0 Original line number Diff line number Diff line 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 }