Skip to content

Commit

Permalink
Teardown Implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Fittipaldi committed Oct 28, 2024
1 parent f50c71c commit 69983fc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 15 deletions.
6 changes: 5 additions & 1 deletion quisp/messages/connection_setup_messages.msg
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ packet ConnectionSetupResponse extends Header
}

packet InternalTerminatedRulesetIdsNotifier extends Header {
unsigned long terminated_rulesets_ids[] @appender(appendTerminatedRulesetId);
unsigned long terminated_rulesets_ids[] @getter(getTerminatedRulesetId) @appender(appendTerminatedRulesetId) @sizeGetter(getNumberOfTerminatedRulesets);
}

packet ConnectionTeardown extends Header {
unsigned long RuleSet_id;
}
4 changes: 4 additions & 0 deletions quisp/modules/Common/Router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ void Router::handleMessage(cMessage *msg) {
bubble("Terminated rulesets IDs list received");
send(pk, "cmPort$o");
return;
} else if (dest_addr == my_address && dynamic_cast<ConnectionTeardown *>(msg)) {
bubble("Connection Teardown received");
send(pk, "cmPort$o");
return;
}

// RoutingDaemon sends hello packet without desination specified
Expand Down
55 changes: 41 additions & 14 deletions quisp/modules/QRSA/ConnectionManager/ConnectionManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@ void ConnectionManager::handleMessage(cMessage *msg) {
}

if (auto *pk = dynamic_cast<InternalTerminatedRulesetIdsNotifier *>(msg)) {
delete msg;
teardownConnections(pk);
return;
}

if (auto *td = dynamic_cast<ConnectionTeardown *>(msg)) {
reservation_register.deleteReservationByRulesetId(td->getRuleSet_id());
}
}

PurType ConnectionManager::parsePurType(const std::string &pur_type) {
Expand Down Expand Up @@ -254,23 +258,32 @@ void ConnectionManager::respondToRequest(ConnectionSetupRequest *req) {
return;
}

ruleset_gen::RuleSetGenerator ruleset_gen{my_address};
const auto &rulesets = ruleset_gen.generateRuleSets(req, createUniqueId());
auto connection_setup_request_id = req->getConnectionSetupRequestId();
auto ruleset_id = createUniqueId();
ruleset_gen::RuleSetGenerator ruleset_gen{my_address};
const auto &rulesets = ruleset_gen.generateRuleSets(req, ruleset_id);

connection_teardown_messages[ruleset_id].clear();
// distribute rulesets to each qnode in the path
for (auto [owner_address, rs] : rulesets) {
ConnectionSetupResponse *pkt = new ConnectionSetupResponse("ConnectionSetupResponse");
pkt->setApplicationId(application_id);
pkt->setConnectionSetupRequestId(connection_setup_request_id);
pkt->setRuleSet(rs);
pkt->setSrcAddr(my_address);
pkt->setDestAddr(owner_address);
pkt->setActual_srcAddr(my_address);
pkt->setActual_destAddr(owner_address);
pkt->setApplication_type(0);
pkt->setKind(2);
send(pkt, "RouterPort$o");
ConnectionSetupResponse *resp = new ConnectionSetupResponse("ConnectionSetupResponse");
resp->setApplicationId(application_id);
resp->setConnectionSetupRequestId(connection_setup_request_id);
resp->setRuleSet(rs);
resp->setRuleSet_id(ruleset_id);
resp->setSrcAddr(my_address);
resp->setDestAddr(owner_address);
resp->setActual_srcAddr(my_address);
resp->setActual_destAddr(owner_address);
resp->setApplication_type(0);
resp->setKind(2);
send(resp, "RouterPort$o");

ConnectionTeardown *td = new ConnectionTeardown("ConnectionTeardown");
td->setSrcAddr(my_address);
td->setDestAddr(owner_address);
td->setRuleSet_id(ruleset_id);
connection_teardown_messages[ruleset_id].push_back(td);
}
reservation_register.registerReservation(qnic_addr, connection_setup_request_id);
}
Expand Down Expand Up @@ -448,4 +461,18 @@ void ConnectionManager::scheduleRequestRetry(int qnic_address) {
return;
}

void ConnectionManager::teardownConnections(messages::InternalTerminatedRulesetIdsNotifier *pkt) {
if (connection_teardown_messages.size() > 0) {
int terminated_rulesets_number = pkt->getNumberOfTerminatedRulesets();
for (int i = 0; i < terminated_rulesets_number; i++) {
auto search = connection_teardown_messages.find(pkt->getTerminatedRulesetId(i));
if (search == connection_teardown_messages.end())
error("ConnectionManager Error: Trying to tear down a connection but the related ConnectionTeardown messages are not ready. This is likely a bug in the code.");
auto messages_to_send = search->second;
for (auto msg : messages_to_send) {
send(msg, "RouterPort$o");
}
}
}
}
} // namespace quisp::modules
4 changes: 4 additions & 0 deletions quisp/modules/QRSA/ConnectionManager/ConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ConnectionManager : public IConnectionManager, public Logger::LoggerBase {
rules::PurType purification_type;
IRoutingDaemon *routing_daemon;
IHardwareMonitor *hardware_monitor;
std::map<unsigned long, std::vector<messages::ConnectionTeardown *>>
connection_teardown_messages; // This map stores the CTMs for every connection for which this node is the responder.

void initialize() override;
void handleMessage(cMessage *msg) override;
Expand All @@ -101,6 +103,8 @@ class ConnectionManager : public IConnectionManager, public Logger::LoggerBase {
// void releaseQnic(int qnic_address);
// bool isQnicBusy(int qnic_address);

void teardownConnections(messages::InternalTerminatedRulesetIdsNotifier *pkt);

static rules::PurType parsePurType(const std::string &pur_type);

unsigned long createUniqueId() override;
Expand Down
1 change: 1 addition & 0 deletions quisp/simulations/simulation_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ network = networks.Simple_MM
**.qrsa.hm.link_tomography = true
**.qrsa.hm.initial_purification = 0
**.qrsa.hm.purification_type = ""
**.EndNode1.is_initiator = true

[Config NoErrorMSM]
network = networks.Simple_MSM
Expand Down

0 comments on commit 69983fc

Please sign in to comment.