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());
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();
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());
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;
179 if (slotDuration == 0)
182 slot.start = slotStart;
183 slot.duration = slotDuration;
184 schedule->slots.push_back(slot);
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;
192 schedules.push_back(schedule);
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());
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;