INET Framework for OMNeT++/OMNEST
inet::GateScheduleConfiguratorBase Class Referenceabstract

#include <GateScheduleConfiguratorBase.h>

Inheritance diagram for inet::GateScheduleConfiguratorBase:
inet::NetworkConfiguratorBase inet::AlwaysOpenGateScheduleConfigurator inet::EagerGateScheduleConfigurator inet::TSNschedGateScheduleConfigurator inet::Z3GateScheduleConfigurator

Classes

class  Input
 
class  Output
 

Public Member Functions

virtual ~GateScheduleConfiguratorBase ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleParameterChange (const char *name) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void clearConfiguration ()
 
virtual void computeConfiguration ()
 
virtual InputcreateGateSchedulingInput () const
 
virtual void addDevices (Input &input) const
 
virtual void addSwitches (Input &input) const
 
virtual void addPorts (Input &input) const
 
virtual void addFlows (Input &input) const
 
virtual void configureGateScheduling ()
 
virtual void configureGateScheduling (cModule *networkNode, cModule *gate, Interface *interface)
 
virtual void configureApplicationOffsets ()
 
virtual OutputcomputeGateScheduling (const Input &input) const =0
 
- Protected Member Functions inherited from inet::NetworkConfiguratorBase
virtual ~NetworkConfiguratorBase ()
 
virtual int numInitStages () const override
 
virtual void extractTopology (Topology &topology)
 Extracts network topology by walking through the module hierarchy. More...
 
virtual std::vector< Node * > computeShortestNodePath (Node *source, Node *destination) const
 
virtual std::vector< Link * > computeShortestLinkPath (Node *source, Node *destination) const
 
virtual bool isBridgeNode (Node *node) const
 
virtual LinkfindLinkIn (const Node *node, const char *neighbor) const
 
virtual LinkfindLinkOut (const Node *node, const char *neighbor) const
 
virtual LinkfindLinkOut (const Node *node, const Node *neighbor) const
 
virtual LinkfindLinkOut (const Interface *interface) const
 
virtual Topology::LinkfindLinkOut (const Node *node, int gateId) const
 
virtual InterfacefindInterface (const Node *node, NetworkInterface *networkInterface) const
 

Protected Attributes

simtime_t gateCycleDuration
 
cValueArray * configuration = nullptr
 
InputgateSchedulingInput = nullptr
 
OutputgateSchedulingOutput = nullptr
 
- Protected Attributes inherited from inet::NetworkConfiguratorBase
Topologytopology = nullptr
 

Constructor & Destructor Documentation

◆ ~GateScheduleConfiguratorBase()

virtual inet::GateScheduleConfiguratorBase::~GateScheduleConfiguratorBase ( )
inlinevirtual
223 { clearConfiguration(); }

Member Function Documentation

◆ addDevices()

void inet::GateScheduleConfiguratorBase::addDevices ( Input input) const
protectedvirtual
73 {
74  for (int i = 0; i < topology->getNumNodes(); i++) {
75  auto node = (Node *)topology->getNode(i);
76  if (!isBridgeNode(node)) {
77  auto device = new Input::Device();
78  device->module = node->module;
79  input.devices.push_back(device);
80  input.networkNodes.push_back(device);
81  }
82  }
83 }

Referenced by createGateSchedulingInput().

◆ addFlows()

void inet::GateScheduleConfiguratorBase::addFlows ( Input input) const
protectedvirtual
142 {
143  int flowIndex = 0;
144  EV_DEBUG << "Computing flows from configuration" << EV_FIELD(configuration) << EV_ENDL;
145  for (int k = 0; k < configuration->size(); k++) {
146  auto entry = check_and_cast<cValueMap *>(configuration->get(k).objectValue());
147  for (int i = 0; i < topology->getNumNodes(); i++) {
148  auto sourceNode = (Node *)topology->getNode(i);
149  cModule *source = sourceNode->module;
150  for (int j = 0; j < topology->getNumNodes(); j++) {
151  auto destinationNode = (Node *)topology->getNode(j);
152  cModule *destination = destinationNode->module;
153  PatternMatcher sourceMatcher(entry->get("source").stringValue(), true, false, false);
154  PatternMatcher destinationMatcher(entry->get("destination").stringValue(), true, false, false);
155  if (sourceMatcher.matches(sourceNode->module->getFullPath().c_str()) &&
156  destinationMatcher.matches(destinationNode->module->getFullPath().c_str()))
157  {
158  int pcp = entry->get("pcp").intValue();
159  int gateIndex = entry->get("gateIndex").intValue();
160  b packetLength = b(entry->get("packetLength").doubleValueInUnit("b"));
161  simtime_t packetInterval = entry->get("packetInterval").doubleValueInUnit("s");
162  simtime_t maxLatency = entry->containsKey("maxLatency") ? entry->get("maxLatency").doubleValueInUnit("s") : -1;
163  simtime_t maxJitter = entry->containsKey("maxJitter") ? entry->get("maxJitter").doubleValueInUnit("s") : 0;
164  bps datarate = packetLength / s(packetInterval.dbl());
165  auto startDevice = input.getDevice(source);
166  auto endDevice = input.getDevice(destination);
167  auto startApplication = new Input::Application();
168  auto startApplicationModule = startDevice->module->getModuleByPath((std::string(".") + std::string(entry->get("application").stringValue())).c_str());
169  if (startApplicationModule == nullptr)
170  throw cRuntimeError("Cannot find flow start application, path = %s", entry->get("application").stringValue());
171  startApplication->module = startApplicationModule;
172  startApplication->device = startDevice;
173  startApplication->pcp = pcp;
174  startApplication->packetLength = packetLength;
175  startApplication->packetInterval = packetInterval;
176  startApplication->maxLatency = maxLatency;
177  startApplication->maxJitter = maxJitter;
178  input.applications.push_back(startApplication);
179  EV_DEBUG << "Adding flow from configuration" << EV_FIELD(source) << EV_FIELD(destination) << EV_FIELD(pcp) << EV_FIELD(packetLength) << EV_FIELD(packetInterval, packetInterval.ustr()) << EV_FIELD(datarate) << EV_FIELD(maxLatency, maxLatency.ustr()) << EV_FIELD(maxJitter, maxJitter.ustr()) << EV_ENDL;
180  auto flow = new Input::Flow();
181  flow->name = entry->containsKey("name") ? entry->get("name").stringValue() : (std::string("flow") + std::to_string(flowIndex++)).c_str();
182  flow->gateIndex = gateIndex;
183  flow->startApplication = startApplication;
184  flow->endDevice = endDevice;
185  cValueArray *pathFragments;
186  if (entry->containsKey("pathFragments"))
187  pathFragments = check_and_cast<cValueArray *>(entry->get("pathFragments").objectValue());
188  else {
189  auto pathFragment = new cValueArray();
190  for (auto node : computeShortestNodePath(sourceNode, destinationNode))
191  pathFragment->add(node->module->getFullName());
192  pathFragments = new cValueArray();
193  pathFragments->add(pathFragment);
194  }
195  for (int l = 0; l < pathFragments->size(); l++) {
196  auto path = new Input::PathFragment();
197  auto pathFragment = check_and_cast<cValueArray *>(pathFragments->get(l).objectValue());
198  for (int m = 0; m < pathFragment->size(); m++) {
199  for (auto networkNode : input.networkNodes) {
200  auto name = pathFragment->get(m).stdstringValue();
201  int index = name.find('.');
202  auto nodeName = index != std::string::npos ? name.substr(0, index) : name;
203  auto interfaceName = index != std::string::npos ? name.substr(index + 1) : "";
204  if (networkNode->module->getFullName() == nodeName) {
205  if (m != pathFragment->size() - 1) {
206  auto startNode = networkNode;
207  auto endNodeName = pathFragment->get(m + 1).stdstringValue();
208  int index = endNodeName.find('.');
209  endNodeName = index != std::string::npos ? endNodeName.substr(0, index) : endNodeName;
210  auto outputPort = *std::find_if(startNode->ports.begin(), startNode->ports.end(), [&] (const auto& port) {
211  return port->endNode->module->getFullName() == endNodeName && (interfaceName == "" || interfaceName == check_and_cast<NetworkInterface *>(port->module)->getInterfaceName());
212  });
213  path->outputPorts.push_back(outputPort);
214  path->inputPorts.push_back(outputPort->otherPort);
215  }
216  path->networkNodes.push_back(networkNode);
217  break;
218  }
219  }
220  }
221  flow->pathFragments.push_back(path);
222  }
223  if (!entry->containsKey("pathFragments"))
224  delete pathFragments;
225  input.flows.push_back(flow);
226  }
227  }
228  }
229  }
230  std::sort(input.flows.begin(), input.flows.end(), [] (const Input::Flow *r1, const Input::Flow *r2) {
231  return r1->startApplication->pcp > r2->startApplication->pcp;
232  });
233 }

Referenced by createGateSchedulingInput().

◆ addPorts()

void inet::GateScheduleConfiguratorBase::addPorts ( Input input) const
protectedvirtual
99 {
100  for (int i = 0; i < topology->getNumNodes(); i++) {
101  auto node = (Node *)topology->getNode(i);
102  auto networkNode = input.getNetworkNode(node->module);
103  for (auto interface : node->interfaces) {
104  auto networkInterface = interface->networkInterface;
105  if (!networkInterface->isLoopback()) {
106  auto subqueue = networkInterface->findModuleByPath(".macLayer.queue.queue[0]");
107  auto port = new Input::Port();
108  port->numGates = subqueue != nullptr ? subqueue->getVectorSize() : -1;
109  port->module = interface->networkInterface;
110  port->datarate = bps(interface->networkInterface->getDatarate());
111  port->propagationTime = check_and_cast<cDatarateChannel *>(interface->networkInterface->getTxTransmissionChannel())->getDelay();
112  port->maxPacketLength = B(interface->networkInterface->getMtu());
113  port->guardBand = s(port->maxPacketLength / port->datarate).get();
114  port->maxCycleTime = gateCycleDuration;
115  port->maxSlotDuration = gateCycleDuration;
116  port->startNode = networkNode;
117  networkNode->ports.push_back(port);
118  input.ports.push_back(port);
119  }
120  }
121  }
122  for (auto networkNode : input.networkNodes) {
123  auto node = check_and_cast<Node *>(topology->getNodeFor(networkNode->module));
124  for (auto port : networkNode->ports) {
125  auto networkInterface = check_and_cast<NetworkInterface *>(port->module);
126  auto link = findLinkOut(findInterface(node, networkInterface));
127  auto linkOut = findLinkOut(node, networkInterface->getNodeOutputGateId());
128  auto remoteNode = check_and_cast<Node *>(linkOut->getLinkOutRemoteNode());
129  port->endNode = *std::find_if(input.networkNodes.begin(), input.networkNodes.end(), [&] (const auto& networkNode) {
130  return networkNode->module == remoteNode->module;
131  });
132  port->otherPort = *std::find_if(input.ports.begin(), input.ports.end(), [&] (const auto& otherPort) {
133  return otherPort->module == link->destinationInterface->networkInterface;
134  });
135  ASSERT(port->endNode);
136  ASSERT(port->otherPort);
137  }
138  }
139 }

Referenced by createGateSchedulingInput().

◆ addSwitches()

void inet::GateScheduleConfiguratorBase::addSwitches ( Input input) const
protectedvirtual
86 {
87  for (int i = 0; i < topology->getNumNodes(); i++) {
88  auto node = (Node *)topology->getNode(i);
89  if (isBridgeNode(node)) {
90  auto switch_ = new Input::Switch();
91  switch_->module = node->module;
92  input.switches.push_back(switch_);
93  input.networkNodes.push_back(switch_);
94  }
95  }
96 }

Referenced by createGateSchedulingInput().

◆ clearConfiguration()

void inet::GateScheduleConfiguratorBase::clearConfiguration ( )
protectedvirtual
42 {
43  if (topology != nullptr)
44  topology->clear();
45  delete gateSchedulingInput;
46  gateSchedulingInput = nullptr;
47  delete gateSchedulingOutput;
48  gateSchedulingOutput = nullptr;
49 }

Referenced by handleParameterChange().

◆ computeConfiguration()

void inet::GateScheduleConfiguratorBase::computeConfiguration ( )
protectedvirtual
52 {
53  long startTime = clock();
54  delete topology;
55  topology = new Topology();
59  printElapsedTime("computeConfiguration", startTime);
60 }

Referenced by handleParameterChange(), and initialize().

◆ computeGateScheduling()

virtual Output* inet::GateScheduleConfiguratorBase::computeGateScheduling ( const Input input) const
protectedpure virtual

◆ configureApplicationOffsets()

void inet::GateScheduleConfiguratorBase::configureApplicationOffsets ( )
protectedvirtual
300 {
301  for (auto& it : gateSchedulingOutput->applicationStartTimes) {
302  auto startOffset = it.second;
303  auto applicationModule = it.first->module;
304  EV_DEBUG << "Setting initial packet production offset for application source" << EV_FIELD(applicationModule) << EV_FIELD(startOffset) << EV_ENDL;
305  auto sourceModule = applicationModule->getSubmodule("source");
306  sourceModule->par("initialProductionOffset") = startOffset.dbl();
307  }
308 }

Referenced by handleParameterChange(), and initialize().

◆ configureGateScheduling() [1/2]

void inet::GateScheduleConfiguratorBase::configureGateScheduling ( )
protectedvirtual
236 {
237  for (int i = 0; i < topology->getNumNodes(); i++) {
238  auto node = (Node *)topology->getNode(i);
239  auto networkNode = node->module;
240  for (auto interface : node->interfaces) {
241  auto queue = interface->networkInterface->findModuleByPath(".macLayer.queue");
242  if (queue != nullptr) {
243  for (cModule::SubmoduleIterator it(queue); !it.end(); ++it) {
244  cModule *gate = *it;
245  if (dynamic_cast<queueing::PeriodicGate *>(gate) != nullptr)
246  configureGateScheduling(networkNode, gate, interface);
247  }
248  }
249  }
250  }
251 }

Referenced by handleParameterChange(), and initialize().

◆ configureGateScheduling() [2/2]

void inet::GateScheduleConfiguratorBase::configureGateScheduling ( cModule *  networkNode,
cModule *  gate,
Interface interface 
)
protectedvirtual
254 {
255  auto networkInterface = interface->networkInterface;
256  bool initiallyOpen = false;
257  simtime_t offset = 0;
258  simtime_t slotEnd = 0;
259  int gateIndex = gate->getIndex();
260  auto port = gateSchedulingInput->getPort(networkInterface);
261  auto it = gateSchedulingOutput->gateSchedules.find(port);
262  if (it == gateSchedulingOutput->gateSchedules.end())
263  throw cRuntimeError("Cannot find schedule for interface, interface = %s", networkInterface->getInterfaceFullPath().c_str());
264  auto& schedules = it->second;
265  if (gateIndex >= schedules.size())
266  throw cRuntimeError("Cannot find schedule for traffic class, interface = %s, gate index = %d", port->module->getFullPath().c_str(), gateIndex);
267  auto schedule = schedules[gateIndex];
268  cValueArray *durations = new cValueArray();
269  for (auto& slot : schedule->slots) {
270  simtime_t slotStart = slot.start;
271  simtime_t slotDuration = slot.duration;
272  if (slotStart < 0 || slotStart + slotDuration > gateCycleDuration)
273  throw cRuntimeError("Invalid slot start and/or duration");
274  if (slotStart == 0)
275  initiallyOpen = true;
276  else {
277  simtime_t duration = slotStart - slotEnd;
278  ASSERT(duration >= 0);
279  durations->add(cValue(duration.dbl(), "s"));
280  }
281  durations->add(cValue(slotDuration.dbl(), "s"));
282  slotEnd = slotStart + slotDuration;
283  }
284  simtime_t remainingDuration = schedule->cycleDuration - slotEnd;
285  if (slotEnd != 0) {
286  if (remainingDuration != 0)
287  durations->add(cValue(remainingDuration.dbl(), "s"));
288  if (durations->size() % 2 != 0)
289  durations->add(cValue(0, "s"));
290  }
291  EV_DEBUG << "Configuring gate scheduling parameters" << EV_FIELD(networkNode) << EV_FIELD(networkInterface) << EV_FIELD(gate) << EV_FIELD(initiallyOpen) << EV_FIELD(offset) << EV_FIELD(durations) << EV_ENDL;
292  gate->par("initiallyOpen") = initiallyOpen;
293  gate->par("offset") = offset.dbl();
294  cPar& durationsPar = gate->par("durations");
295  durationsPar.copyIfShared();
296  durationsPar.setObjectValue(durations);
297 }

◆ createGateSchedulingInput()

GateScheduleConfiguratorBase::Input * inet::GateScheduleConfiguratorBase::createGateSchedulingInput ( ) const
protectedvirtual
63 {
64  auto input = new Input();
65  addDevices(*input);
66  addSwitches(*input);
67  addPorts(*input);
68  addFlows(*input);
69  return input;
70 }

Referenced by computeConfiguration().

◆ handleMessage()

virtual void inet::GateScheduleConfiguratorBase::handleMessage ( cMessage *  msg)
inlineoverrideprotectedvirtual

Reimplemented from inet::NetworkConfiguratorBase.

205 { throw cRuntimeError("this module doesn't handle messages, it runs only in initialize()"); }

◆ handleParameterChange()

void inet::GateScheduleConfiguratorBase::handleParameterChange ( const char *  name)
overrideprotectedvirtual
29 {
30  if (name != nullptr) {
31  if (!strcmp(name, "configuration")) {
32  configuration = check_and_cast<cValueArray *>(par("configuration").objectValue());
37  }
38  }
39 }

◆ initialize()

void inet::GateScheduleConfiguratorBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented in inet::Z3GateScheduleConfigurator.

16 {
17  if (stage == INITSTAGE_LOCAL) {
18  gateCycleDuration = par("gateCycleDuration");
19  configuration = check_and_cast<cValueArray *>(par("configuration").objectValue());
20  }
21  if (stage == INITSTAGE_QUEUEING) {
25  }
26 }

Referenced by inet::Z3GateScheduleConfigurator::initialize().

Member Data Documentation

◆ configuration

cValueArray* inet::GateScheduleConfiguratorBase::configuration = nullptr
protected

◆ gateCycleDuration

◆ gateSchedulingInput

Input* inet::GateScheduleConfiguratorBase::gateSchedulingInput = nullptr
protected

◆ gateSchedulingOutput

Output* inet::GateScheduleConfiguratorBase::gateSchedulingOutput = nullptr
protected

The documentation for this class was generated from the following files:
inet::NetworkConfiguratorBase::findLinkOut
virtual Link * findLinkOut(const Node *node, const char *neighbor) const
Definition: NetworkConfiguratorBase.cc:116
inet::NetworkConfiguratorBase::Node::module
cModule * module
Definition: NetworkConfiguratorBase.h:28
inet::GateScheduleConfiguratorBase::gateSchedulingOutput
Output * gateSchedulingOutput
Definition: GateScheduleConfiguratorBase.h:200
inet::sort
void sort(std::vector< T > &v)
Definition: stlutils.h:129
inet::GateScheduleConfiguratorBase::gateSchedulingInput
Input * gateSchedulingInput
Definition: GateScheduleConfiguratorBase.h:199
inet::units::units::bps
compose< b, pow< s, -1 > > bps
Definition: Units.h:1169
inet::Topology::getNodeFor
Node * getNodeFor(cModule *mod) const
Returns the graph node which corresponds to the given module in the network.
Definition: Topology.cc:355
inet::GateScheduleConfiguratorBase::configureApplicationOffsets
virtual void configureApplicationOffsets()
Definition: GateScheduleConfiguratorBase.cc:299
inet::GateScheduleConfiguratorBase::addDevices
virtual void addDevices(Input &input) const
Definition: GateScheduleConfiguratorBase.cc:72
inet::INITSTAGE_QUEUEING
INET_API InitStage INITSTAGE_QUEUEING
Initialization of queueing modules.
inet::Topology::getNode
Node * getNode(int i) const
Returns pointer to the ith node in the graph.
Definition: Topology.cc:348
inet::GateScheduleConfiguratorBase::clearConfiguration
virtual void clearConfiguration()
Definition: GateScheduleConfiguratorBase.cc:41
inet::GateScheduleConfiguratorBase::computeConfiguration
virtual void computeConfiguration()
Definition: GateScheduleConfiguratorBase.cc:51
inet::Topology::clear
void clear()
Deletes the topology stored in the object.
Definition: Topology.cc:78
inet::GateScheduleConfiguratorBase::addPorts
virtual void addPorts(Input &input) const
Definition: GateScheduleConfiguratorBase.cc:98
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::NetworkConfiguratorBase::findInterface
virtual Interface * findInterface(const Node *node, NetworkInterface *networkInterface) const
Definition: NetworkConfiguratorBase.cc:150
inet::NetworkConfiguratorBase::extractTopology
virtual void extractTopology(Topology &topology)
Extracts network topology by walking through the module hierarchy.
Definition: NetworkConfiguratorBase.cc:19
inet::GateScheduleConfiguratorBase::gateCycleDuration
simtime_t gateCycleDuration
Definition: GateScheduleConfiguratorBase.h:195
inet::GateScheduleConfiguratorBase::addFlows
virtual void addFlows(Input &input) const
Definition: GateScheduleConfiguratorBase.cc:141
inet::GateScheduleConfiguratorBase::computeGateScheduling
virtual Output * computeGateScheduling(const Input &input) const =0
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::Topology::getNumNodes
int getNumNodes() const
Returns the number of nodes in the graph.
Definition: Topology.h:516
inet::physicallayer::k
const double k
Definition: Qam1024Modulation.cc:14
inet::GateScheduleConfiguratorBase::Input::getPort
Port * getPort(cModule *module)
Definition: GateScheduleConfiguratorBase.h:135
inet::GateScheduleConfiguratorBase::createGateSchedulingInput
virtual Input * createGateSchedulingInput() const
Definition: GateScheduleConfiguratorBase.cc:62
inet::GateScheduleConfiguratorBase::configureGateScheduling
virtual void configureGateScheduling()
Definition: GateScheduleConfiguratorBase.cc:235
inet::GateScheduleConfiguratorBase::configuration
cValueArray * configuration
Definition: GateScheduleConfiguratorBase.h:196
TIME
#define TIME(CODE)
Definition: INETDefs.h:96
inet::NetworkConfiguratorBase::topology
Topology * topology
Definition: NetworkConfiguratorBase.h:67
inet::units::values::m
value< double, units::m > m
Definition: Units.h:1233
inet::GateScheduleConfiguratorBase::Output::applicationStartTimes
std::map< Input::Application *, simtime_t > applicationStartTimes
Definition: GateScheduleConfiguratorBase.h:183
inet::GateScheduleConfiguratorBase::Output::gateSchedules
std::map< Input::Port *, std::vector< Schedule * > > gateSchedules
Definition: GateScheduleConfiguratorBase.h:182
inet::GateScheduleConfiguratorBase::addSwitches
virtual void addSwitches(Input &input) const
Definition: GateScheduleConfiguratorBase.cc:85
EV_ENDL
#define EV_ENDL
Definition: INETDefs.h:114
inet::printElapsedTime
void printElapsedTime(const char *name, long startTime)
Definition: INETDefs.h:91
inet::NetworkConfiguratorBase::isBridgeNode
virtual bool isBridgeNode(Node *node) const
Definition: NetworkConfiguratorBase.cc:103
inet::NetworkConfiguratorBase::computeShortestNodePath
virtual std::vector< Node * > computeShortestNodePath(Node *source, Node *destination) const
Definition: NetworkConfiguratorBase.cc:77