Skip to content

Commit

Permalink
Merge pull request #474 from sfc-aqua/remove-qnic-id-and-type-from-rs
Browse files Browse the repository at this point in the history
Remove qnic id and type from RuleSet
  • Loading branch information
zigen authored Jan 19, 2023
2 parents 4df3aaf + 745b205 commit 454fcd9
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 815 deletions.
224 changes: 34 additions & 190 deletions quisp/modules/QRSA/ConnectionManager/ConnectionManager.cc

Large diffs are not rendered by default.

74 changes: 39 additions & 35 deletions quisp/modules/QRSA/ConnectionManager/ConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
* Author: zigen
*/

#ifndef MODULES_CONNECTIONMANAGER_H_
#define MODULES_CONNECTIONMANAGER_H_
#pragma once

#include <omnetpp.h>
#include <queue>
#include <vector>

#include "IConnectionManager.h"
#include "modules/Logger/LoggerBase.h"

using namespace omnetpp;
using namespace quisp::messages;
using quisp::rules::PurType;
#include <messages/classical_messages.h>
#include <modules/Logger/LoggerBase.h>
#include <modules/QNIC.h>
#include <modules/QRSA/HardwareMonitor/IHardwareMonitor.h>
#include <modules/QRSA/RoutingDaemon/IRoutingDaemon.h>
#include <rules/Action.h>
#include <utils/ComponentProvider.h>

struct SwappingConfig {
int left_partner;
int lres;
int right_partner;
int rres;
};

namespace quisp {
namespace modules {
namespace quisp::modules {

/** \class ConnectionManager ConnectionManager.cc
*
Expand Down Expand Up @@ -49,64 +61,56 @@ class ConnectionManager : public IConnectionManager, public Logger::LoggerBase {
protected:
int my_address;
int num_of_qnics;
std::map<int, std::queue<ConnectionSetupRequest *>> connection_setup_buffer; // key is qnic address
std::map<int, std::queue<messages::ConnectionSetupRequest *>> connection_setup_buffer; // key is qnic address
std::map<int, int> connection_retry_count; // key is qnic address
std::vector<int> reserved_qnics = {}; // reserved qnic address table
std::vector<cMessage *> request_send_timing; // self message, notification for sending out request
bool simultaneous_es_enabled;
bool es_with_purify = false;
int num_remote_purification;
double threshold_fidelity;
PurType purification_type;
rules::PurType purification_type;
IRoutingDaemon *routing_daemon;
IHardwareMonitor *hardware_monitor;

void initialize() override;
void handleMessage(cMessage *msg) override;
void finish() override;

void respondToRequest(ConnectionSetupRequest *pk);
void respondToRequest_deprecated(ConnectionSetupRequest *pk);
void tryRelayRequestToNextHop(ConnectionSetupRequest *pk);
void respondToRequest(messages::ConnectionSetupRequest *pk);
void respondToRequest_deprecated(messages::ConnectionSetupRequest *pk);
void tryRelayRequestToNextHop(messages::ConnectionSetupRequest *pk);

void queueApplicationRequest(ConnectionSetupRequest *pk);
void queueApplicationRequest(messages::ConnectionSetupRequest *pk);
void initiateApplicationRequest(int qnic_address);
void scheduleRequestRetry(int qnic_address);
void popApplicationRequest(int qnic_address);

void storeRuleSetForApplication(ConnectionSetupResponse *pk);
void storeRuleSet(ConnectionSetupResponse *pk);
void storeRuleSetForApplication(messages::ConnectionSetupResponse *pk);
void storeRuleSet(messages::ConnectionSetupResponse *pk);

void initiator_reject_req_handler(RejectConnectionSetupRequest *pk);
void responder_reject_req_handler(RejectConnectionSetupRequest *pk);
void intermediate_reject_req_handler(RejectConnectionSetupRequest *pk);
void initiator_reject_req_handler(messages::RejectConnectionSetupRequest *pk);
void responder_reject_req_handler(messages::RejectConnectionSetupRequest *pk);
void intermediate_reject_req_handler(messages::RejectConnectionSetupRequest *pk);

void rejectRequest(ConnectionSetupRequest *req);
void rejectRequest(messages::ConnectionSetupRequest *req);

SwappingConfig generateSwappingConfig(int swapper_address, std::vector<int> path, std::map<int, std::vector<int>> swapping_partners, std::vector<QNIC_pair_info> qnics,
int num_resources);
SwappingConfig generateSimultaneousSwappingConfig(int swapper_address, std::vector<int> path, std::vector<QNIC_pair_info> qnics, int num_resources);

std::unique_ptr<Rule> purifyRule(int partner_address, PurType purification_type, double threshold_fidelity, QNIC_type qnic_type, int qnic_id, int shared_tag,
std::string name = "purification");
std::unique_ptr<Rule> swapRule(std::vector<int> partner_address, double threshold_fidelity, std::vector<QNIC_type> qnic_type, std::vector<int> qnic_id,
std::vector<QNIC_type> remote_qnic_type, std::vector<int> remote_qnic_id, std::vector<int> remote_qnic_address, int shared_tag,
std::string name = "swapping");
std::unique_ptr<Rule> waitRule(int partner_address, QNIC_type qnic_type, int qnic_id, int shared_tag, std::string name = "wait");
std::unique_ptr<Rule> tomographyRule(int partner_address, int owner_address, int num_measure, double threshold_fidelity, QNIC_type qnic_type, int qnic_id, int shared_tag,
std::string name = "tomography");

std::unique_ptr<rules::Rule> purifyRule(int partner_address, rules::PurType purification_type, double threshold_fidelity, int shared_tag, std::string name = "purification");
std::unique_ptr<rules::Rule> swapRule(std::vector<int> partner_address, double threshold_fidelity, int shared_tag, std::string name = "swapping");
std::unique_ptr<rules::Rule> waitRule(int partner_address, int shared_tag, std::string name = "wait");
std::unique_ptr<rules::Rule> tomographyRule(int partner_address, int owner_address, int num_measure, double threshold_fidelity, int shared_tag, std::string name = "tomography");
void reserveQnic(int qnic_address);
void releaseQnic(int qnic_address);
bool isQnicBusy(int qnic_address);
QNIC_id getQnicInterface(int owner_address, int partner_address, std::vector<int> path, std::vector<QNIC_pair_info> qnics);

static int computePathDivisionSize(int l);
static int fillPathDivision(std::vector<int> path, int i, int l, int *link_left, int *link_right, int *swapper, int fill_start);
static PurType parsePurType(const std::string &pur_type);
static rules::PurType parsePurType(const std::string &pur_type);

unsigned long createUniqueId() override;
};

} // namespace modules
} // namespace quisp
#endif /* MODULES_CONNECTIONMANAGER_H_ */
} // namespace quisp::modules
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TEST(ConnectionManagerRuleSetTest, PurificationRule) {
int qnic_id = 4;
double threshold_fidelity = 0;

auto purification_rule = connection_manager.purifyRule(partner_addr, purification_type, threshold_fidelity, qnic_type, qnic_id, 0);
auto purification_rule = connection_manager.purifyRule(partner_addr, purification_type, threshold_fidelity, 0);
EXPECT_EQ(purification_rule->rule_id, -1);
EXPECT_EQ(purification_rule->name, "purification");

Expand All @@ -64,7 +64,7 @@ TEST(ConnectionManagerRuleSetTest, PurificationRule) {
"name":"purification",
"shared_tag": 0,
"interface":[
{"partner_address": 1, "qnic_type": "QNIC_E", "qnic_id": 4}
{"partner_address": 1}
],
"condition":{
"clauses":[
Expand All @@ -74,9 +74,7 @@ TEST(ConnectionManagerRuleSetTest, PurificationRule) {
"num_resource":3,
"required_fidelity":0.0,
"interface":{
"partner_address":1,
"qnic_type":"QNIC_E",
"qnic_id":4
"partner_address":1
}
}
}
Expand All @@ -87,7 +85,7 @@ TEST(ConnectionManagerRuleSetTest, PurificationRule) {
"options":{
"purification_type":"DOUBLE",
"interface": [
{"partner_address":1,"qnic_type":"QNIC_E","qnic_id":4}
{"partner_address":1}
]
}
}
Expand All @@ -108,7 +106,7 @@ TEST(ConnectionManagerRuleSetTest, SwapRule) {
std::vector<int> remote_qnic_address = {11, 12};
double threshold_fidelity = 0;

auto purification_rule = connection_manager.swapRule(partner_addr, threshold_fidelity, qnic_type, qnic_id, remote_qnic_type, remote_qnic_id, remote_qnic_address, 0);
auto purification_rule = connection_manager.swapRule(partner_addr, threshold_fidelity, 0);
EXPECT_EQ(purification_rule->rule_id, -1);
EXPECT_EQ(purification_rule->name, "swapping");

Expand All @@ -120,8 +118,8 @@ TEST(ConnectionManagerRuleSetTest, SwapRule) {
"name":"swapping",
"shared_tag": 0,
"interface":[
{"partner_address": 1, "qnic_type": "QNIC_E", "qnic_id": 4},
{"partner_address": 3, "qnic_type": "QNIC_R", "qnic_id": 5}
{"partner_address": 1},
{"partner_address": 3}
],
"condition":{
"clauses":[
Expand All @@ -131,9 +129,7 @@ TEST(ConnectionManagerRuleSetTest, SwapRule) {
"num_resource":1,
"required_fidelity":0.0,
"interface": {
"partner_address":1,
"qnic_type":"QNIC_E",
"qnic_id":4
"partner_address":1
}
}
},
Expand All @@ -143,9 +139,7 @@ TEST(ConnectionManagerRuleSetTest, SwapRule) {
"num_resource":1,
"required_fidelity":0.0,
"interface":{
"partner_address":3,
"qnic_type":"QNIC_R",
"qnic_id":5
"partner_address":3
}
}
}
Expand All @@ -155,12 +149,12 @@ TEST(ConnectionManagerRuleSetTest, SwapRule) {
"type":"swapping",
"options":{
"interface":[
{"partner_address": 1, "qnic_type": "QNIC_E", "qnic_id": 4},
{"partner_address": 3, "qnic_type": "QNIC_R", "qnic_id": 5}
{"partner_address": 1},
{"partner_address": 3}
],
"remote_interface": [
{"partner_address": 1, "qnic_type": "QNIC_R", "qnic_id": 3, "qnic_address": 11},
{"partner_address": 3, "qnic_type": "QNIC_E", "qnic_id": 6, "qnic_address": 12}
{"partner_address": 1},
{"partner_address": 3}
]
}
}
Expand All @@ -178,7 +172,7 @@ TEST(ConnectionManagerRuleSetTest, waitRule) {
int qnic_id = 4;
int shared_tag = 0;

auto purification_rule = connection_manager.waitRule(partner_addr, qnic_type, qnic_id, shared_tag);
auto purification_rule = connection_manager.waitRule(partner_addr, shared_tag);
EXPECT_EQ(purification_rule->rule_id, -1);
EXPECT_EQ(purification_rule->name, "wait");

Expand All @@ -190,17 +184,15 @@ TEST(ConnectionManagerRuleSetTest, waitRule) {
"name":"wait",
"shared_tag": 0,
"interface":[
{"partner_address": 1, "qnic_type": "QNIC_E", "qnic_id": 4}
{"partner_address": 1}
],
"condition":{
"clauses":[
{
"type":"wait",
"options":{
"interface":{
"partner_address": 1,
"qnic_type":"QNIC_E",
"qnic_id":4
"partner_address": 1
}
}
}
Expand All @@ -210,7 +202,7 @@ TEST(ConnectionManagerRuleSetTest, waitRule) {
"type":"wait",
"options":{
"interface":[
{"partner_address": 1, "qnic_type": "QNIC_E", "qnic_id": 4}
{"partner_address": 1}
]
}
}
Expand All @@ -231,7 +223,7 @@ TEST(ConnectionManagerRuleSetTest, tomographyRule) {
double threshold_fidelity = 0;
int shared_tag = 3;

auto tomography_rule = connection_manager.tomographyRule(partner_addr, owner_addr, num_measurement, threshold_fidelity, qnic_type, qnic_id, shared_tag);
auto tomography_rule = connection_manager.tomographyRule(partner_addr, owner_addr, num_measurement, threshold_fidelity, shared_tag);
EXPECT_EQ(tomography_rule->rule_id, -1);
EXPECT_EQ(tomography_rule->name, "tomography");

Expand All @@ -241,9 +233,7 @@ TEST(ConnectionManagerRuleSetTest, tomographyRule) {
"action": {
"options": {
"interface": [{
"partner_address": 1,
"qnic_id": 4,
"qnic_type": "QNIC_E"
"partner_address": 1
}],
"num_measure": 5000,
"owner_address": 2
Expand All @@ -254,9 +244,7 @@ TEST(ConnectionManagerRuleSetTest, tomographyRule) {
"clauses": [{
"options": {
"interface": {
"partner_address": 1,
"qnic_id": 4,
"qnic_type": "QNIC_E"
"partner_address": 1
},
"num_resource": 1,
"required_fidelity": 0.0
Expand All @@ -265,19 +253,15 @@ TEST(ConnectionManagerRuleSetTest, tomographyRule) {
}, {
"options": {
"interface": {
"partner_address": 1,
"qnic_id": 4,
"qnic_type": "QNIC_E"
"partner_address": 1
},
"num_measure": 5000
},
"type": "measure_count"
}]
},
"interface": [{
"partner_address": 1,
"qnic_id": 4,
"qnic_type": "QNIC_E"
"partner_address": 1
}],
"shared_tag": 3,
"name": "tomography",
Expand Down
Loading

0 comments on commit 454fcd9

Please sign in to comment.