• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sfc-aqua / quisp / 8099990924

29 Feb 2024 05:17PM UTC coverage: 41.578% (-0.8%) from 42.352%
8099990924

Pull #545

github

web-flow
Merge c2570a20a into 274af93d1
Pull Request #545: Add satellite links

82 of 404 new or added lines in 13 files covered. (20.3%)

6 existing lines in 4 files now uncovered.

2799 of 6732 relevant lines covered (41.58%)

38008.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.03
/quisp/modules/Common/Router.cc
1
/** \file Router.cc
2
 *  \authors takaakimatsuo
3
 *
4
 *  \brief Router
5
 */
6
#include "Router.h"
7
#include "messages/BSA_ipc_messages_m.h"
8
#include "messages/classical_messages.h"  //Path selection: type = 1, Timing notifier for BMA: type = 4
9
#include "messages/link_generation_messages_m.h"
10

11
using namespace omnetpp;
12
using namespace quisp::messages;
13

14
namespace quisp::modules {
15

16
Router::Router() : provider(utils::ComponentProvider{this}) {}
19✔
17

18
void Router::initialize() {
19✔
19
  my_address = provider.getNodeAddr();
19✔
20

21
  // Topology creation for routing table
22
  auto topo = provider.getTopologyForRouter();
19✔
23

24
  // If no node with the parameter & value found, do nothing.
25
  if (topo->getNumNodes() == 0 || topo == nullptr) {
19✔
26
    return;
19✔
27
  }
19✔
28

29
  generateRoutingTable(topo);
×
30
}
×
31

32
void Router::generateRoutingTable(cTopology *topo) {
×
33
  cTopology::Node *thisNode = topo->getNodeFor(getParentModule());  // The parent node with this specific router
×
34

35
  // Traverse through all the destinations from the thisNode
36
  for (int i = 0; i < topo->getNumNodes(); i++) {
×
37
    const auto node = topo->getNode(i);
×
38
    // skip the node that is running this specific router app
39
    if (node == thisNode) continue;
×
40

41
    // Apply dijkstra to each node to find all shortest paths.
42
    topo->calculateWeightedSingleShortestPathsTo(topo->getNode(i));
×
43

44
    // Overwrites getNumPaths() and so on.
45
    // Check the number of shortest paths towards the target node.
46
    // This may be more than 1 if multiple paths have the same minimum cost.
47

48
    if (thisNode->getNumPaths() == 0) continue;
×
49

50
    // Returns the next link/gate in the ith shortest paths towards the target node.
51
    cGate *parentModuleGate = thisNode->getPath(0)->getLocalGate();
×
52
    int gateIndex = parentModuleGate->getIndex();
×
53
    int address = topo->getNode(i)->getModule()->par("address");
×
54

55
    // Store gate index per destination from this node
56
    routing_table[address] = gateIndex;
×
57

58
    if (strstr(parentModuleGate->getFullName(), "quantum")) {
×
59
      error("Classical routing table referring to quantum gates...");
×
60
    }
×
61
  }
×
62
}
×
63

64
void Router::handleMessage(cMessage *msg) {
24✔
65
  const int unidentified_destination = -1;
24✔
66
  // check the header of the received package
67
  Header *pk = check_and_cast<Header *>(msg);
24✔
68
  int dest_addr = pk->getDestAddr();
24✔
69
  int who_are_you = pk->getKind();
24✔
70

71
  // If destination is this node: Path selection
72
  if (dest_addr == my_address && who_are_you == 1) {
24✔
73
    send(pk, "toApp");
×
74
    return;
×
75
  } else if (dest_addr == my_address && dynamic_cast<BSMTimingNotification *>(msg)) {  // Timing for BSM
24✔
76
    bubble("Timing Notifier from BSA (stand-alone or internal) received");
1✔
77
    send(pk, "rePort$o");  // send to Application locally
1✔
78
    return;
1✔
79
  } else if (dest_addr == my_address && dynamic_cast<EPPSTimingNotification *>(msg)) {  // Timing for BSM
23✔
80
    bubble("Timing Notifier from EPPS received");
1✔
81
    send(pk, "rePort$o");  // send to Application locally
1✔
82
    return;
1✔
83
  } else if (dest_addr == my_address && dynamic_cast<SingleClickResult *>(msg)) {
22✔
84
    bubble("Single click result from BSA received");
×
85
    send(pk, "rePort$o");
×
86
    return;
×
87
  } else if (dest_addr == my_address && dynamic_cast<MSMResult *>(msg)) {
22✔
88
    bubble("MSM BSA result from partner RE received");
×
89
    send(pk, "rePort$o");
×
90
    return;
×
91
  } else if (dest_addr == my_address && dynamic_cast<StopEPPSEmission *>(msg)) {
22✔
92
    bubble("Stop EPPS emission signal received");
×
93
    send(pk, "toApp");
×
94
    return;
×
95
  } else if (dest_addr == my_address && dynamic_cast<ConnectionSetupRequest *>(msg)) {
22✔
96
    bubble("Connection setup request received");
1✔
97
    send(pk, "cmPort$o");
1✔
98
    return;
1✔
99
  } else if (dest_addr == my_address && dynamic_cast<ConnectionSetupResponse *>(msg)) {
21✔
100
    bubble("Connection setup response received");
1✔
101
    send(pk, "cmPort$o");
1✔
102
    return;
1✔
103
  } else if (dest_addr == my_address && dynamic_cast<RejectConnectionSetupRequest *>(msg)) {
20✔
104
    bubble("Reject connection setup response received");
1✔
105
    send(pk, "cmPort$o");
1✔
106
    return;
1✔
107
  } else if (dest_addr == my_address && dynamic_cast<InternalRuleSetForwarding *>(msg)) {
19✔
108
    bubble("Internal RuleSet Forwarding packet received");
1✔
109
    send(pk, "rePort$o");
1✔
110
    return;
1✔
111
  } else if (dest_addr == my_address && dynamic_cast<InternalRuleSetForwarding_Application *>(msg)) {
18✔
112
    bubble("Internal RuleSet Forwarding Application packet received");
1✔
113
    send(pk, "rePort$o");
1✔
114
    return;
1✔
115
  } else if (dest_addr == my_address && dynamic_cast<SwappingResult *>(msg)) {
17✔
116
    bubble("Swapping Result packet received");
1✔
117
    send(pk, "rePort$o");
1✔
118
    return;
1✔
119
  } else if (dest_addr == my_address && dynamic_cast<LinkTomographyRequest *>(msg)) {
16✔
120
    bubble("Link tomography request received");
1✔
121
    send(pk, "hmPort$o");
1✔
122
    return;
1✔
123
  } else if (dest_addr == my_address && dynamic_cast<LinkTomographyAck *>(msg)) {
15✔
124
    bubble("Link tomography ack received");
1✔
125
    send(pk, "hmPort$o");
1✔
126
    return;
1✔
127
  } else if (dest_addr == my_address && dynamic_cast<LinkTomographyRuleSet *>(msg)) {
14✔
128
    bubble("Link tomography rule set received");
1✔
129
    send(pk, "rePort$o");
1✔
130
    return;
1✔
131
  } else if (dest_addr == my_address && dynamic_cast<LinkTomographyResult *>(msg)) {
13✔
132
    bubble("Link tomography result received");
×
133
    send(pk, "hmPort$o");
×
134
    return;
×
135
  } else if (dest_addr == my_address && dynamic_cast<PurificationResult *>(msg)) {
13✔
136
    bubble("Purification result received");
1✔
137
    send(pk, "rePort$o");
1✔
138
    return;
1✔
139
  } else if (dest_addr == my_address && dynamic_cast<StopEmitting *>(msg)) {
12✔
140
    send(pk, "rePort$o");
1✔
141
    return;
1✔
142
  } else if (dest_addr == my_address && dynamic_cast<OspfPacket *>(msg)) {
11✔
143
    send(pk, "rdPort$o");
6✔
144
    return;
6✔
145
  }
6✔
146

147
  // RoutingDaemon sends hello packet without desination specified
148
  if (dest_addr == unidentified_destination && dynamic_cast<OspfHelloPacket *>(msg)) {
5✔
149
    handleOspfHelloPacket(msg);
3✔
150
    return;
3✔
151
  }
3✔
152

153
  // Check if packet is reachable
154
  if (!routing_table.count(dest_addr)) {
2✔
155
    std::cout << "In Node[" << my_address << "]Address... " << dest_addr << " unreachable, discarding packet " << pk->getName() << endl;
1✔
156
    delete pk;
1✔
157
    error("Router couldn't find the path. Shoudn't happen. Or maybe the router does not understand the packet.");
1✔
158
    return;
1✔
159
  }
1✔
160

161
  int out_gate_index = routing_table.at(dest_addr);
1✔
162
  pk->setHopCount(pk->getHopCount() + 1);
1✔
163
  send(pk, "toQueue", out_gate_index);
1✔
164
}
1✔
165

166
void Router::handleOspfHelloPacket(cMessage *msg) {
3✔
167
  auto pk = dynamic_cast<OspfHelloPacket *>(msg);
3✔
168
  if (!parentModuleIsQNode()) {
3✔
169
    nonQNodeForwardOspfPacket(pk);
1✔
170
    return;
1✔
171
  }
1✔
172

173
  const bool dst_is_this_node = (pk->getSrcAddr() != my_address);
2✔
174
  if (dst_is_this_node) {
2✔
175
    redirectOspfHelloPacketToRoutingDaemon(pk);
1✔
176
  } else {
1✔
177
    sendOspfHelloPacketToQueue(pk);
1✔
178
  }
1✔
179
}
2✔
180

NEW
181
bool Router::parentModuleIsQNode() {
×
NEW
182
  return (provider.getNode()->getModuleType() == cModuleType::get("modules.QNode") || provider.getNode()->getModuleType() == cModuleType::get("modules.QNode_Sat"));
×
NEW
183
}
×
184

185
/**
186
 * @details Unlike QNodes, BSA nodes are connected to only two nodes (at least that is the assumption)
187
 *          So this function simulates BSA nodes receiving packets from one node, and sending them to the other node.
188
 */
189
void Router::nonQNodeForwardOspfPacket(OspfPacket *pk) {
1✔
190
  pk->setHopCount(pk->getHopCount() + 1);
1✔
191
  const int gate_index_to_pk_src = pk->getArrivalGate()->getIndex();
1✔
192
  const int gate_index_to_pk_dst = gate_index_to_pk_src == 0 ? 1 : 0;
1✔
193
  send(pk, "toQueue", gate_index_to_pk_dst);
1✔
194
}
1✔
195

196
void Router::sendOspfHelloPacketToQueue(OspfPacket *pk) {
1✔
197
  pk->setHopCount(pk->getHopCount() + 1);
1✔
198
  const int gate_index_to_pk_dst = pk->getSendingGateIndex();
1✔
199
  send(pk, "toQueue", gate_index_to_pk_dst);
1✔
200
}
1✔
201

202
void Router::redirectOspfHelloPacketToRoutingDaemon(OspfPacket *pk) { send(pk, "rdPort$o"); }
1✔
203

204
}  // namespace quisp::modules
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc