INET Framework for OMNeT++/OMNEST
inet::TSNschedGateScheduleConfigurator Class Reference

#include <TSNschedGateScheduleConfigurator.h>

Inheritance diagram for inet::TSNschedGateScheduleConfigurator:
inet::GateScheduleConfiguratorBase inet::NetworkConfiguratorBase

Protected Member Functions

virtual cValueMap * convertInputToJson (const Input &input) const
 
virtual OutputconvertJsonToOutput (const Input &input, const cValueMap *json) const
 
virtual void writeInputToFile (const Input &input, std::string fileName) const
 
virtual OutputreadOutputFromFile (const Input &input, std::string fileName) const
 
virtual void executeTSNsched (std::string fileName) const
 
virtual OutputcomputeGateScheduling (const Input &input) const override
 
- Protected Member Functions inherited from inet::GateScheduleConfiguratorBase
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 ()
 
- 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
 

Additional Inherited Members

- Public Member Functions inherited from inet::GateScheduleConfiguratorBase
virtual ~GateScheduleConfiguratorBase ()
 
- Protected Attributes inherited from inet::GateScheduleConfiguratorBase
simtime_t gateCycleDuration
 
cValueArray * configuration = nullptr
 
InputgateSchedulingInput = nullptr
 
OutputgateSchedulingOutput = nullptr
 
- Protected Attributes inherited from inet::NetworkConfiguratorBase
Topologytopology = nullptr
 

Member Function Documentation

◆ computeGateScheduling()

TSNschedGateScheduleConfigurator::Output * inet::TSNschedGateScheduleConfigurator::computeGateScheduling ( const Input input) const
overrideprotectedvirtual

Implements inet::GateScheduleConfiguratorBase.

249 {
250  std::string baseName = getEnvir()->getConfig()->substituteVariables("${resultdir}/${configname}-${iterationvarsf}#${repetition}");
251  std::string inputFileName = baseName + "-TSNsched-input.json";
252  // TODO: std::string outputFileName = baseName + "-TSNsched-output.json";
253  std::string outputFileName = "output.json";
254  std::remove(outputFileName.c_str());
255  writeInputToFile(input, inputFileName);
256  executeTSNsched(inputFileName);
257  return readOutputFromFile(input, outputFileName);
258 }

◆ convertInputToJson()

cValueMap * inet::TSNschedGateScheduleConfigurator::convertInputToJson ( const Input input) const
protectedvirtual
59 {
60  cValueMap *json = new cValueMap();
61  cValueArray *jsonDevices = new cValueArray();
62  json->set("devices", jsonDevices);
63  for (auto device : input.devices) {
64  cValueMap *jsonDevice = new cValueMap();
65  jsonDevices->add(jsonDevice);
66  jsonDevice->set("name", device->module->getFullName());
67  }
68  cValueArray *jsonSwitches = new cValueArray();
69  json->set("switches", jsonSwitches);
70  for (int i = 0; i < input.switches.size(); i++) {
71  auto switch_ = input.switches[i];
72  cValueMap *jsonSwitch = new cValueMap();
73  jsonSwitches->add(jsonSwitch);
74  // TODO KLUDGE this is a wild guess
75  double guardBand = 0;
76  for (auto flow : input.flows) {
77  double v = b(flow->startApplication->packetLength).get();
78  if (guardBand < v)
79  guardBand = v;
80  }
81  auto jsonPorts = new cValueArray();
82  jsonSwitch->set("name", switch_->module->getFullName());
83  jsonSwitch->set("ports", jsonPorts);
84  for (int j = 0; j < switch_->ports.size(); j++) {
85  auto port = switch_->ports[j];
86  auto jsonPort = new cValueMap();
87  jsonPorts->add(jsonPort);
88  // KLUDGE: port name should not be unique in the network but only in the network node
89  std::string nodeName = port->startNode->module->getFullName();
90  jsonPort->set("name", nodeName + "-" + port->module->getFullName());
91  jsonPort->set("connectsTo", port->endNode->module->getFullName());
92  jsonPort->set("timeToTravel", port->propagationTime.dbl() * 1000000);
93  jsonPort->set("timeToTravelUnit", "us");
94 // jsonPort->set("guardBandSize", guardBand);
95 // jsonPort->set("guardBandSizeUnit", "bit");
96  jsonPort->set("portSpeed", bps(port->datarate).get() / 1000000);
97  jsonPort->set("portSpeedSizeUnit", "bit");
98  jsonPort->set("portSpeedTimeUnit", "us");
99  jsonPort->set("scheduleType", "Hypercycle");
100  jsonPort->set("cycleStart", 0);
101  jsonPort->set("cycleStartUnit", "us");
102  jsonPort->set("maximumSlotDuration", gateCycleDuration.dbl() * 1000000);
103  jsonPort->set("maximumSlotDurationUnit", "us");
104  }
105  }
106  cValueArray *jsonFlows = new cValueArray();
107  json->set("flows", jsonFlows);
108  for (auto flow : input.flows) {
109  cValueMap *jsonFlow = new cValueMap();
110  jsonFlows->add(jsonFlow);
111  jsonFlow->set("name", flow->name);
112  jsonFlow->set("type", "unicast");
113  jsonFlow->set("sourceDevice", flow->startApplication->device->module->getFullName());
114  jsonFlow->set("fixedPriority", "true");
115  jsonFlow->set("priorityValue", flow->gateIndex);
116  jsonFlow->set("packetPeriodicity", flow->startApplication->packetInterval.dbl() * 1000000);
117  jsonFlow->set("packetPeriodicityUnit", "us");
118  jsonFlow->set("packetSize", b(flow->startApplication->packetLength).get());
119  jsonFlow->set("packetSizeUnit", "bit");
120  jsonFlow->set("hardConstraintTime", flow->startApplication->maxLatency.dbl() * 1000000);
121  jsonFlow->set("hardConstraintTimeUnit", "us");
122  cValueArray *endDevices = new cValueArray();
123  jsonFlow->set("endDevices", endDevices);
124  endDevices->add(cValue(flow->endDevice->module->getFullName()));
125  cValueArray *hops = new cValueArray();
126  jsonFlow->set("hops", hops);
127  for (int j = 0; j < flow->pathFragments.size(); j++) {
128  auto pathFragment = flow->pathFragments[j];
129  for (int k = 0; k < pathFragment->networkNodes.size() - 1; k++) {
130  auto networkNode = pathFragment->networkNodes[k];
131  auto nextNetworkNode = pathFragment->networkNodes[k + 1];
132  cValueMap *hop = new cValueMap();
133  hops->add(hop);
134  hop->set("currentNodeName", networkNode->module->getFullName());
135  hop->set("nextNodeName", nextNetworkNode->module->getFullName());
136  }
137  }
138  }
139  return json;
140 }

Referenced by writeInputToFile().

◆ convertJsonToOutput()

TSNschedGateScheduleConfigurator::Output * inet::TSNschedGateScheduleConfigurator::convertJsonToOutput ( const Input input,
const cValueMap *  json 
) const
protectedvirtual
143 {
144  auto output = new Output();
145  auto jsonSwitches = check_and_cast<cValueArray *>(json->get("switches").objectValue());
146  for (int i = 0; i < jsonSwitches->size(); i++) {
147  auto jsonSwitch = check_and_cast<cValueMap *>(jsonSwitches->get(i).objectValue());
148  std::string switchName = jsonSwitch->get("name").stringValue();
149  auto it = std::find_if(input.switches.begin(), input.switches.end(), [&] (Input::Switch *switch_) { return switch_->module->getFullName() == switchName; });
150  if (it == input.switches.end())
151  throw cRuntimeError("Cannot find switch: %s", switchName.c_str());
152  auto switch_ = *it;
153  auto jsonPorts = check_and_cast<cValueArray *>(jsonSwitch->get("ports").objectValue());
154  for (int j = 0; j < jsonPorts->size(); j++) {
155  auto jsonPort = check_and_cast<cValueMap *>(jsonPorts->get(j).objectValue());
156  std::string portName = jsonPort->get("name").stringValue();
157  // KLUDGE: port name should not be unique in the network but only in the network node
158  portName = portName.substr(portName.find('-') + 1);
159  auto jt = std::find_if(switch_->ports.begin(), switch_->ports.end(), [&] (Input::Port *port) { return port->startNode == switch_ && port->module->getFullName() == portName; });
160  if (jt == switch_->ports.end())
161  throw cRuntimeError("Cannot find port: %s", portName.c_str());
162  auto port = *jt;
163  auto& schedules = output->gateSchedules[port];
164  for (int gateIndex = 0; gateIndex < port->numGates; gateIndex++) {
165  auto schedule = new Output::Schedule();
166  schedule->port = port;
167  schedule->gateIndex = gateIndex;
168  schedule->cycleDuration = jsonPort->get("cycleDuration").doubleValue() / 1000000;
169  auto jsonPrioritySlots = check_and_cast<cValueArray *>(jsonPort->get("prioritySlotsData").objectValue());
170  for (int k = 0; k < jsonPrioritySlots->size(); k++) {
171  auto jsonPrioritySlot = check_and_cast<cValueMap *>(jsonPrioritySlots->get(k).objectValue());
172  if (gateIndex == jsonPrioritySlot->get("priority").intValue()) {
173  auto jsonSlots = check_and_cast<cValueArray *>(jsonPrioritySlot->get("slotsData").objectValue());
174  for (int l = 0; l < jsonSlots->size(); l++) {
175  auto jsonSlot = check_and_cast<cValueMap *>(jsonSlots->get(l).objectValue());
176  simtime_t slotStart = jsonSlot->get("slotStart").doubleValue() / 1000000;
177  simtime_t slotDuration = jsonSlot->get("slotDuration").doubleValue() / 1000000;
178  // slot with length 0 are not used
179  if (slotDuration == 0)
180  continue;
181  Output::Slot slot;
182  slot.start = slotStart;
183  slot.duration = slotDuration;
184  schedule->slots.push_back(slot);
185  }
186  }
187  }
188  auto& slots = schedule->slots;
189  std::sort(slots.begin(), slots.end(), [] (const Output::Slot& slot1, const Output::Slot& slot2) {
190  return slot1.start < slot2.start;
191  });
192  schedules.push_back(schedule);
193  }
194  }
195  }
196  auto jsonFlows = check_and_cast<cValueArray *>(json->get("flows").objectValue());
197  for (int i = 0; i < jsonFlows->size(); i++) {
198  auto jsonFlow = check_and_cast<cValueMap *>(jsonFlows->get(i).objectValue());
199  std::string name = jsonFlow->get("name").stringValue();
200  auto it = std::find_if(input.flows.begin(), input.flows.end(), [&] (Input::Flow *flow) { return flow->name == name; });
201  if (it == input.flows.end())
202  throw cRuntimeError("Cannot find flow: %s", name.c_str());
203  auto flow = *it;
204  auto application = flow->startApplication;
205  auto firstSendingTime = jsonFlow->get("firstSendingTime").doubleValue() / 1000000;
206  bps datarate = application->device->ports[0]->datarate;
207  auto startTime = firstSendingTime - s(application->packetLength / datarate).get();
208  while (startTime < 0)
209  startTime += application->packetInterval.dbl();
210  output->applicationStartTimes[application] = startTime;
211  }
212  return output;
213 }

Referenced by readOutputFromFile().

◆ executeTSNsched()

void inet::TSNschedGateScheduleConfigurator::executeTSNsched ( std::string  fileName) const
protectedvirtual
241 {
242  std::string classpath = "${TSNSCHED_HOME}/libs/com.microsoft.z3.jar";
243  std::string command = std::string("java -classpath ") + classpath + " -jar ${TSNSCHED_HOME}/libs/TSNsched.jar " + inputFileName + " -enableConsoleOutput";
244  if (std::system(command.c_str()) != 0)
245  throw cRuntimeError("TSNsched command execution failed, make sure TSNSCHED_HOME is set and Microsoft Z3 is installed");
246 }

Referenced by computeGateScheduling().

◆ readOutputFromFile()

TSNschedGateScheduleConfigurator::Output * inet::TSNschedGateScheduleConfigurator::readOutputFromFile ( const Input input,
std::string  fileName 
) const
protectedvirtual
227 {
228  std::ifstream stream(fileName.c_str());
229  if (!stream.good())
230  throw cRuntimeError("Cannot read from TSNsched output file");
231  std::string expression = std::string("readJSON(\"") + fileName + "\")";
232  cDynamicExpression dynamicExression;
233  dynamicExression.parse(expression.c_str());
234  auto json = check_and_cast<cValueMap *>(dynamicExression.evaluate().objectValue());
235  auto output = convertJsonToOutput(input, json);
236  delete json;
237  return output;
238 }

Referenced by computeGateScheduling().

◆ writeInputToFile()

void inet::TSNschedGateScheduleConfigurator::writeInputToFile ( const Input input,
std::string  fileName 
) const
protectedvirtual
216 {
217  auto json = convertInputToJson(input);
218  std::ofstream stream;
219  stream.open(fileName.c_str());
220  if (stream.fail())
221  throw cRuntimeError("Cannot open file %s", fileName.c_str());
222  printJson(stream, cValue(json));
223  delete json;
224 }

Referenced by computeGateScheduling().


The documentation for this class was generated from the following files:
inet::TSNschedGateScheduleConfigurator::convertInputToJson
virtual cValueMap * convertInputToJson(const Input &input) const
Definition: TSNschedGateScheduleConfigurator.cc:58
inet::TSNschedGateScheduleConfigurator::executeTSNsched
virtual void executeTSNsched(std::string fileName) const
Definition: TSNschedGateScheduleConfigurator.cc:240
inet::sort
void sort(std::vector< T > &v)
Definition: stlutils.h:129
inet::units::units::bps
compose< b, pow< s, -1 > > bps
Definition: Units.h:1169
inet::remove
void remove(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:107
inet::TSNschedGateScheduleConfigurator::readOutputFromFile
virtual Output * readOutputFromFile(const Input &input, std::string fileName) const
Definition: TSNschedGateScheduleConfigurator.cc:226
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::GateScheduleConfiguratorBase::gateCycleDuration
simtime_t gateCycleDuration
Definition: GateScheduleConfiguratorBase.h:195
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::TSNschedGateScheduleConfigurator::convertJsonToOutput
virtual Output * convertJsonToOutput(const Input &input, const cValueMap *json) const
Definition: TSNschedGateScheduleConfigurator.cc:142
inet::physicallayer::k
const double k
Definition: Qam1024Modulation.cc:14
inet::TSNschedGateScheduleConfigurator::writeInputToFile
virtual void writeInputToFile(const Input &input, std::string fileName) const
Definition: TSNschedGateScheduleConfigurator.cc:215