12 |
13 | // nedtool version check
14 | #define MSGC_VERSION 0x0501
15 | #if (MSGC_VERSION!=OMNETPP_VERSION)
16 | # error Version mismatch! Probably this file was generated by an earlier version of nedtool: 'make clean' should help.
17 | #endif
18 |
19 |
20 | namespace ecsnetpp {
21 |
22 | // cplusplus {{
23 | #include "omnetpp.h"
24 | // }}
25 |
26 | /**
27 | * Class generated from msg/StreamingMessage.msg:32 by nedtool.
28 | *
29 | * //
30 | * // TODO generated message class
31 | * //
32 | * packet StreamingMessage
33 | * {
34 | * int messageId;
35 | * string sender;
36 | * // int size;
37 | * string content;
38 | * bool isProcessingDelayInCyclesPerEvent;
39 | * // double cyclesPerEvent;
40 | * double processingDelayPerEvent;
41 | * double selectivityRatio;
42 | * simtime_t startTime;
43 | * simtime_t operatorIngressTime;
44 | * simtime_t channelIngressTime;
45 | * double networkDelay;
46 | * double processingDelay;
47 | * double edgeProcessingDelay;
48 | * }
49 | *
50 | */
51 | class StreamingMessage : public ::omnetpp::cPacket
52 | {
53 | protected:
54 | int messageId;
55 | ::omnetpp::opp_string sender;
56 | ::omnetpp::opp_string content;
57 | bool isProcessingDelayInCyclesPerEvent;
58 | double processingDelayPerEvent;
59 | double selectivityRatio;
60 | ::omnetpp::simtime_t startTime;
61 | ::omnetpp::simtime_t operatorIngressTime;
62 | ::omnetpp::simtime_t channelIngressTime;
63 | double networkDelay;
64 | double processingDelay;
65 | double edgeProcessingDelay;
66 |
67 | private:
68 | void copy(const StreamingMessage& other);
69 |
70 | protected:
71 | // protected and unimplemented operator==(), to prevent accidental usage
72 | bool operator==(const StreamingMessage&);
73 |
74 | public:
75 | StreamingMessage(const char *name=nullptr, short kind=0);
76 | StreamingMessage(const StreamingMessage& other);
77 | virtual ~StreamingMessage();
78 | StreamingMessage& operator=(const StreamingMessage& other);
79 | virtual StreamingMessage *dup() const override {return new StreamingMessage(*this);}
80 | virtual void parsimPack(omnetpp::cCommBuffer *b) const override;
81 | virtual void parsimUnpack(omnetpp::cCommBuffer *b) override;
82 |
83 | // field getter/setter methods
84 | virtual int getMessageId() const;
85 | virtual void setMessageId(int messageId);
86 | virtual const char * getSender() const;
87 | virtual void setSender(const char * sender);
88 | virtual const char * getContent() const;
89 | virtual void setContent(const char * content);
90 | virtual bool getIsProcessingDelayInCyclesPerEvent() const;
91 | virtual void setIsProcessingDelayInCyclesPerEvent(bool isProcessingDelayInCyclesPerEvent);
92 | virtual double getProcessingDelayPerEvent() const;
93 | virtual void setProcessingDelayPerEvent(double processingDelayPerEvent);
94 | virtual double getSelectivityRatio() const;
95 | virtual void setSelectivityRatio(double selectivityRatio);
96 | virtual ::omnetpp::simtime_t getStartTime() const;
97 | virtual void setStartTime(::omnetpp::simtime_t startTime);
98 | virtual ::omnetpp::simtime_t getOperatorIngressTime() const;
99 | virtual void setOperatorIngressTime(::omnetpp::simtime_t operatorIngressTime);
100 | virtual ::omnetpp::simtime_t getChannelIngressTime() const;
101 | virtual void setChannelIngressTime(::omnetpp::simtime_t channelIngressTime);
102 | virtual double getNetworkDelay() const;
103 | virtual void setNetworkDelay(double networkDelay);
104 | virtual double getProcessingDelay() const;
105 | virtual void setProcessingDelay(double processingDelay);
106 | virtual double getEdgeProcessingDelay() const;
107 | virtual void setEdgeProcessingDelay(double edgeProcessingDelay);
108 | };
109 |
110 | inline void doParsimPacking(omnetpp::cCommBuffer *b, const StreamingMessage& obj) {obj.parsimPack(b);}
111 | inline void doParsimUnpacking(omnetpp::cCommBuffer *b, StreamingMessage& obj) {obj.parsimUnpack(b);}
112 |
113 | } // namespace ecsnetpp
114 |
115 | #endif // ifndef __ECSNET_STREAMINGMESSAGE_M_H
116 |
117 |
--------------------------------------------------------------------------------
/src/msg/package.ned:
--------------------------------------------------------------------------------
1 | package ecsnetpp.msg;
2 |
3 | @namespace(ecsnetpp);
4 | @license(LGPL);
5 |
--------------------------------------------------------------------------------
/src/networks/.qtenvrc:
--------------------------------------------------------------------------------
1 | [General]
2 | last-configname=General
3 | last-runnumber=0
4 |
--------------------------------------------------------------------------------
/src/networks/package.ned:
--------------------------------------------------------------------------------
1 | package ecsnetpp.networks;
2 |
3 | @namespace(ecsnetpp);
4 | @license(LGPL);
5 |
--------------------------------------------------------------------------------
/src/networks/simpleedgecloudenvironment.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.networks;
17 |
18 | import ecsnetpp.host.RaspberryPiModel2B;
19 | import ecsnetpp.host.RaspberryPiModel3B;
20 | import ecsnetpp.host.CloudNodeA;
21 | import ecsnetpp.builder.TaskBuilder;
22 | import ecsnetpp.builder.ECSBuilder;
23 | import ecsnetpp.common.SimulationController;
24 | import inet.visualizer.integrated.IntegratedCanvasVisualizer;
25 | import inet.networklayer.configurator.ipv4.IPv4NetworkConfigurator;
26 | import inet.physicallayer.ieee80211.packetlevel.Ieee80211ScalarRadioMedium;
27 | import inet.common.lifecycle.LifecycleController;
28 | import inet.common.figures.DelegateSignalConfigurator;
29 | import inet.networklayer.configurator.ipv4.IPv4NetworkConfigurator;
30 | import inet.node.inet.INetworkNode;
31 | import inet.physicallayer.contract.packetlevel.IRadioMedium;
32 | import inet.visualizer.contract.IIntegratedVisualizer;
33 | import inet.node.ethernet.Eth100M;
34 | import inet.node.ethernet.Eth10M;
35 | import inet.node.ethernet.Eth100G;
36 | import inet.node.ethernet.Eth1G;
37 | import inet.node.ethernet.EtherLink;
38 | import inet.node.ethernet.EtherSwitch;
39 | import inet.node.inet.Router;
40 | import inet.node.internetcloud.InternetCloud;
41 | import inet.node.wireless.AccessPoint;
42 | import ned.DatarateChannel;
43 |
44 | network SimpleEdgeCloudEnvironment
45 | {
46 | parameters:
47 | double eToCDelayMean @unit(ms) = default(0ms);
48 | double eToCDelayStdev @unit(ms) = default(0ms);
49 | double eToCDatarate @unit(bps) = default(1Gbps);
50 | bool ackersEnabled = default(false);
51 | bool hasGlobalSupervisor = default(true);
52 | int numPiModel2Bs = default(4);
53 | int numPiModel3Bs = default(4);
54 | string mediumType = default("IdealRadioMedium");
55 | string cloudAddress = default("");
56 | @display("bgb=884.304,707.72797");
57 | types:
58 | channel E2C_low extends DatarateChannel
59 | {
60 | delay = 0;
61 | datarate = eToCDatarate;
62 | }
63 |
64 | channel E2C_high extends DatarateChannel
65 | {
66 | delay = eToCDelayMean;
67 | datarate = eToCDatarate;
68 | }
69 | submodules:
70 | pi2Bs[numPiModel2Bs]: RaspberryPiModel2B;
71 | pi3Bs[numPiModel3Bs]: RaspberryPiModel3B;
72 | stargazer3: CloudNodeA {
73 | @display("p=246.35199,131.008,r");
74 | }
75 | albacore5: Router {
76 | @display("p=331.792,263.44");
77 | }
78 | // switch1: EtherSwitch {
79 | // @display("p=371.664,226.416");
80 | // }
81 | area1AP1: AccessPoint {
82 | @display("p=357.42398,380.208");
83 | }
84 | taskbuilder: ECSBuilder {
85 | @display("p=492.70398,39.871998");
86 | }
87 | simController: SimulationController {
88 | @display("p=783.2,39.871998");
89 | }
90 | radioMedium: Ieee80211ScalarRadioMedium {
91 | @display("p=344.608,38.447998");
92 | }
93 | configurator: IPv4NetworkConfigurator {
94 | @display("p=193.664,38.447998");
95 | }
96 | visualizer: IntegratedCanvasVisualizer {
97 | @display("p=629.408,38.447998");
98 | }
99 | lifecycleController: LifecycleController {
100 | @display("p=24.208,41.295998");
101 | }
102 | connections:
103 | stargazer3.ethg++ <--> E2C_high <--> albacore5.ethg++;
104 | albacore5.ethg++ <--> E2C_low <--> area1AP1.ethg++;
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/src/package.ned:
--------------------------------------------------------------------------------
1 | package ecsnetpp;
2 |
3 | @license(LGPL);
4 |
--------------------------------------------------------------------------------
/src/power/States.h:
--------------------------------------------------------------------------------
1 | /*
2 | * States.h
3 | *
4 | * Created on: Nov 4, 2017
5 | * Author: gayashan
6 | */
7 |
8 | #ifndef POWER_STATES_H_
9 | #define POWER_STATES_H_
10 |
11 | class States {
12 | public:
13 | enum CPUState{
14 | CPU_IDLE,
15 | CPU_BUSY
16 | };
17 | };
18 |
19 |
20 |
21 | #endif /* POWER_STATES_H_ */
22 |
--------------------------------------------------------------------------------
/src/power/consumer/CPUPowerConsumer.cc:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #include "CPUPowerConsumer.h"
17 |
18 | namespace ecsnetpp {
19 |
20 | simsignal_t CPUPowerConsumer::cpuPowerConsumptionChangedSignal = registerSignal("cpuPowerConsumptionChanged");
21 |
22 | Define_Module(CPUPowerConsumer);
23 |
24 | void CPUPowerConsumer::initialize(int stage) {
25 | cSimpleModule::initialize(stage);
26 | if (stage == inet::INITSTAGE_LOCAL) {
27 | cpuBusyUtilisation = par("cpuBusyUtilisation").doubleValue();
28 | cpuIdleUtilisation = par("cpuIdleUtilisation").doubleValue();
29 | cpuPowerConsumptionScalar =
30 | par("cpuPowerConsumptionScalar").doubleValue();
31 | idlePowerConsumption = W(par("idlePowerConsumption"));
32 |
33 | prevState = States::CPU_IDLE;
34 | cModule *host = findContainingNode(this);
35 | host->subscribe(ISTask::cpuStateChangedSignal, this);
36 | powerConsumption = W(0);
37 | WATCH(powerConsumption);
38 | }
39 | }
40 |
41 | W CPUPowerConsumer::computeCPUPowerConsumption(double value) const {
42 | W _powerConsumption = W(0);
43 | if (value == States::CPU_BUSY) {
44 | if (prevState == States::CPU_BUSY) {
45 | _powerConsumption = W(
46 | cpuPowerConsumptionScalar * cpuBusyUtilisation);
47 | } else if (prevState == States::CPU_IDLE) {
48 | _powerConsumption = W(
49 | cpuPowerConsumptionScalar * cpuIdleUtilisation);
50 | }
51 | prevState = States::CPU_BUSY;
52 | } else if (value == States::CPU_IDLE) {
53 | if (prevState == States::CPU_BUSY) {
54 | _powerConsumption = W(
55 | cpuPowerConsumptionScalar * cpuBusyUtilisation);
56 | } else if (prevState == States::CPU_IDLE) {
57 | _powerConsumption = W(
58 | cpuPowerConsumptionScalar * cpuIdleUtilisation);
59 | }
60 | prevState = States::CPU_IDLE;
61 | } else {
62 | _powerConsumption = W(0);
63 | }
64 | // EV << "CPU Power consumption=" << _powerConsumption << endl;
65 | return _powerConsumption;
66 | }
67 |
68 | void CPUPowerConsumer::receiveSignal(cComponent *source, simsignal_t signal,
69 | long value, cObject *details) {
70 |
71 | if (simTime() >= getSimulation()->getWarmupPeriod()) {
72 | if (signal == ISTask::cpuStateChangedSignal) {
73 | powerConsumption = computeCPUPowerConsumption(value);
74 | emit(cpuPowerConsumptionChangedSignal, powerConsumption.get());
75 | } else
76 | throw cRuntimeError("Unknown signal");
77 | }
78 | }
79 |
80 | } /* namespace ecsnetpp */
81 |
--------------------------------------------------------------------------------
/src/power/consumer/CPUPowerConsumer.h:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #ifndef POWER_CONSUMER_CPUPOWERCONSUMER_H_
17 | #define POWER_CONSUMER_CPUPOWERCONSUMER_H_
18 |
19 | #include "inet/power/contract/IEpEnergySource.h"
20 | #include "inet/power/contract/IEpEnergyConsumer.h"
21 | #include "inet/common/ModuleAccess.h"
22 | #include "../../stask/ISTask.h"
23 |
24 | using namespace inet;
25 | using namespace inet::power;
26 |
27 | namespace ecsnetpp {
28 |
29 | class CPUPowerConsumer : public cSimpleModule, public cListener {
30 | protected:
31 | double cpuPowerConsumptionScalar = NaN;
32 | double cpuBusyUtilisation;
33 | double cpuIdleUtilisation;
34 | W idlePowerConsumption = W(NaN);
35 | IEpEnergySource *energySource = nullptr;
36 |
37 | // state
38 | mutable States::CPUState prevState;
39 | W powerConsumption = W(NaN);
40 | public:
41 | static simsignal_t cpuPowerConsumptionChangedSignal;
42 |
43 | protected:
44 | virtual int numInitStages() const override { return NUM_INIT_STAGES; }
45 | virtual void initialize(int stage) override;
46 | virtual W computeCPUPowerConsumption(double value) const;
47 | public:
48 | virtual IEnergySource *getEnergySource() const { return energySource; }
49 | virtual W getPowerConsumption() const {return powerConsumption;}
50 |
51 | virtual void receiveSignal(cComponent *source, simsignal_t signal, long value, cObject *details) override;
52 | };
53 |
54 | } /* namespace ecsnetpp */
55 |
56 | #endif /* POWER_CONSUMER_CPUEPENERGYCONSUMER_H_ */
57 |
--------------------------------------------------------------------------------
/src/power/consumer/CPUPowerConsumer.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.power.consumer;
17 |
18 | simple CPUPowerConsumer
19 | {
20 | parameters:
21 | string energySourceModule;
22 | double cpuPowerConsumptionScalar = default(0);
23 | double cpuBusyUtilisation = default(1);
24 | double cpuIdleUtilisation = default(0);
25 | double idlePowerConsumption @unit(W) = default(0mW);
26 | @display("i=block/cogwheel");
27 | @signal[cpuPowerConsumptionChanged](type=double);
28 | @statistic[cpuPowerConsumption](title="CPU Power consumption"; source=cpuPowerConsumptionChanged; record=vector; interpolationmode=sample-hold);
29 |
30 | @class(CPUPowerConsumer);
31 | }
32 |
--------------------------------------------------------------------------------
/src/power/consumer/NetworkPowerConsumer.cc:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #include "NetworkPowerConsumer.h"
17 |
18 | #include "inet/common/ModuleAccess.h"
19 | #include "../../stask/ISTask.h"
20 |
21 | namespace ecsnetpp {
22 |
23 | simsignal_t NetworkPowerConsumer::networkPowerConsumptionChangedSignal = registerSignal("networkPowerConsumptionChanged");
24 |
25 | Define_Module(NetworkPowerConsumer);
26 |
27 | void NetworkPowerConsumer::initialize(int stage) {
28 | cSimpleModule::initialize(stage);
29 | if (stage == inet::INITSTAGE_LOCAL) {
30 | offPowerConsumption = W(par("offPowerConsumption"));
31 | sleepPowerConsumption = W(par("sleepPowerConsumption"));
32 | switchingPowerConsumption = W(par("switchingPowerConsumption"));
33 | receiverIdlePowerConsumption = W(par("receiverIdlePowerConsumption"));
34 | receiverBusyPowerConsumption = W(par("receiverBusyPowerConsumption"));
35 | receiverReceivingPowerConsumption = W(
36 | par("receiverReceivingPowerConsumption"));
37 | receiverReceivingPreamblePowerConsumption = W(
38 | par("receiverReceivingPreamblePowerConsumption"));
39 | receiverReceivingHeaderPowerConsumption = W(
40 | par("receiverReceivingHeaderPowerConsumption"));
41 | receiverReceivingDataPowerConsumption = W(
42 | par("receiverReceivingDataPowerConsumption"));
43 | transmitterIdlePowerConsumption = W(
44 | par("transmitterIdlePowerConsumption"));
45 | transmitterTransmittingPowerConsumption = W(
46 | par("transmitterTransmittingPowerConsumption"));
47 | transmitterTransmittingPreamblePowerConsumption = W(
48 | par("transmitterTransmittingPreamblePowerConsumption"));
49 | transmitterTransmittingHeaderPowerConsumption = W(
50 | par("transmitterTransmittingHeaderPowerConsumption"));
51 | transmitterTransmittingDataPowerConsumption = W(
52 | par("transmitterTransmittingDataPowerConsumption"));
53 | cpuPowerConsumptionScalar =
54 | par("cpuPowerConsumptionScalar").doubleValue();
55 | cModule *parent = getParentModule();
56 | parent->subscribe(IRadio::radioModeChangedSignal, this);
57 | parent->subscribe(IRadio::receptionStateChangedSignal, this);
58 | parent->subscribe(IRadio::transmissionStateChangedSignal, this);
59 | parent->subscribe(IRadio::receivedSignalPartChangedSignal, this);
60 | parent->subscribe(IRadio::transmittedSignalPartChangedSignal,
61 | this);
62 |
63 | cModule *radioModule = parent->getSubmodule("wlan", 0)->getSubmodule("radio");
64 | radio = check_and_cast(radioModule);
65 | powerConsumption = W(0);
66 | WATCH(powerConsumption);
67 | }
68 | }
69 |
70 | W NetworkPowerConsumer::computePowerConsumption() const
71 | {
72 | IRadio::RadioMode radioMode = radio->getRadioMode();
73 | if (radioMode == IRadio::RADIO_MODE_OFF)
74 | return offPowerConsumption;
75 | else if (radioMode == IRadio::RADIO_MODE_SLEEP)
76 | return sleepPowerConsumption;
77 | else if (radioMode == IRadio::RADIO_MODE_SWITCHING)
78 | return switchingPowerConsumption;
79 | W _powerConsumption = W(0);
80 | IRadio::ReceptionState receptionState = radio->getReceptionState();
81 | IRadio::TransmissionState transmissionState = radio->getTransmissionState();
82 | if (radioMode == IRadio::RADIO_MODE_RECEIVER || radioMode == IRadio::RADIO_MODE_TRANSCEIVER) {
83 | // std::cout << "RCV " << _powerConsumption << endl;
84 | if (receptionState == IRadio::RECEPTION_STATE_IDLE){
85 | _powerConsumption += receiverIdlePowerConsumption;
86 | // std::cout << "RCV receiverIdlePowerConsumption " << _powerConsumption << endl;
87 | } else if (receptionState == IRadio::RECEPTION_STATE_BUSY){
88 | _powerConsumption += receiverBusyPowerConsumption;
89 | // std::cout << "RCV receiverBusyPowerConsumption " << _powerConsumption << endl;
90 | } else if (receptionState == IRadio::RECEPTION_STATE_RECEIVING) {
91 | auto part = radio->getReceivedSignalPart();
92 | if (part == IRadioSignal::SIGNAL_PART_NONE)
93 | ;
94 | else if (part == IRadioSignal::SIGNAL_PART_WHOLE){
95 | _powerConsumption += receiverReceivingPowerConsumption;
96 | // std::cout << "RCV receiverReceivingPowerConsumption " << _powerConsumption << endl;
97 | }else if (part == IRadioSignal::SIGNAL_PART_PREAMBLE){
98 | _powerConsumption += receiverReceivingPreamblePowerConsumption;
99 | // std::cout << "RCV receiverReceivingPreamblePowerConsumption " << _powerConsumption << endl;
100 | }else if (part == IRadioSignal::SIGNAL_PART_HEADER){
101 | _powerConsumption += receiverReceivingHeaderPowerConsumption;
102 | // std::cout << "RCV receiverReceivingHeaderPowerConsumption " << _powerConsumption << endl;
103 | }else if (part == IRadioSignal::SIGNAL_PART_DATA){
104 | _powerConsumption += receiverReceivingDataPowerConsumption;
105 | // std::cout << "RCV receiverReceivingDataPowerConsumption " << _powerConsumption << endl;
106 | }else{
107 | throw cRuntimeError("Unknown received signal part");
108 | // std::cout << "RCV unknown " << _powerConsumption << endl;
109 | }
110 | }
111 | else if (receptionState != IRadio::RECEPTION_STATE_UNDEFINED)
112 | throw cRuntimeError("Unknown radio reception state");
113 | }
114 | if (radioMode == IRadio::RADIO_MODE_TRANSMITTER || radioMode == IRadio::RADIO_MODE_TRANSCEIVER) {
115 | // std::cout << "TRS " << _powerConsumption << endl;
116 | if (transmissionState == IRadio::TRANSMISSION_STATE_IDLE){
117 | _powerConsumption += transmitterIdlePowerConsumption;
118 | // std::cout << "TRS transmitterIdlePowerConsumption " << _powerConsumption << endl;
119 | } else if (transmissionState == IRadio::TRANSMISSION_STATE_TRANSMITTING) {
120 | // TODO: add transmission power?
121 | auto part = radio->getTransmittedSignalPart();
122 | if (part == IRadioSignal::SIGNAL_PART_NONE)
123 | ;
124 | else if (part == IRadioSignal::SIGNAL_PART_WHOLE){
125 | _powerConsumption += transmitterTransmittingPowerConsumption;
126 | // std::cout << "TRS transmitterTransmittingPowerConsumption " << _powerConsumption << endl;
127 | } else if (part == IRadioSignal::SIGNAL_PART_PREAMBLE){
128 | _powerConsumption += transmitterTransmittingPreamblePowerConsumption;
129 | // std::cout << "TRS transmitterTransmittingPreamblePowerConsumption " << _powerConsumption << endl;
130 | } else if (part == IRadioSignal::SIGNAL_PART_HEADER){
131 | _powerConsumption += transmitterTransmittingHeaderPowerConsumption;
132 | // std::cout << "TRS transmitterTransmittingHeaderPowerConsumption " << _powerConsumption << endl;
133 | } else if (part == IRadioSignal::SIGNAL_PART_DATA){
134 | _powerConsumption += transmitterTransmittingDataPowerConsumption;
135 | // std::cout << "TRS transmitterTransmittingDataPowerConsumption " << _powerConsumption << endl;
136 | } else{
137 | throw cRuntimeError("Unknown transmitted signal part");
138 | // std::cout << "TRS unknown " << _powerConsumption << endl;
139 | }
140 | }
141 | else if (transmissionState != IRadio::TRANSMISSION_STATE_UNDEFINED)
142 | throw cRuntimeError("Unknown radio transmission state");
143 | }
144 | // std::cout << "Network Power consumption=" << _powerConsumption << endl;
145 | return _powerConsumption;
146 | }
147 |
148 | void NetworkPowerConsumer::receiveSignal(cComponent *source,
149 | simsignal_t signal, long value, cObject *details) {
150 |
151 | if (simTime() >= getSimulation()->getWarmupPeriod()) {
152 | if (signal == IRadio::radioModeChangedSignal
153 | || signal == IRadio::receptionStateChangedSignal
154 | || signal == IRadio::transmissionStateChangedSignal
155 | || signal == IRadio::receivedSignalPartChangedSignal
156 | || signal == IRadio::transmittedSignalPartChangedSignal) {
157 | powerConsumption = computePowerConsumption();
158 | emit(networkPowerConsumptionChangedSignal, powerConsumption.get());
159 | } else
160 | throw cRuntimeError("Unknown signal");
161 | }
162 | }
163 |
164 | } /* namespace ecsnetpp */
165 |
--------------------------------------------------------------------------------
/src/power/consumer/NetworkPowerConsumer.h:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #ifndef POWER_CONSUMER_NETWORKPOWERCONSUMER_H_
17 | #define POWER_CONSUMER_NETWORKPOWERCONSUMER_H_
18 |
19 | #include "inet/physicallayer/contract/packetlevel/IRadio.h"
20 | #include "inet/power/contract/IEpEnergyConsumer.h"
21 | #include "inet/power/contract/IEpEnergySource.h"
22 |
23 | using namespace inet;
24 | using namespace inet::power;
25 | using namespace inet::physicallayer;
26 |
27 | namespace ecsnetpp {
28 |
29 | class NetworkPowerConsumer: public cSimpleModule, public cListener {
30 |
31 | protected:
32 | double cpuPowerConsumptionScalar = NaN;
33 | // parameters
34 | W offPowerConsumption = W(NaN);
35 | W sleepPowerConsumption = W(NaN);
36 | W switchingPowerConsumption = W(NaN);
37 | W receiverIdlePowerConsumption = W(NaN);
38 | W receiverBusyPowerConsumption = W(NaN);
39 | W receiverReceivingPowerConsumption = W(NaN);
40 | W receiverReceivingPreamblePowerConsumption = W(NaN);
41 | W receiverReceivingHeaderPowerConsumption = W(NaN);
42 | W receiverReceivingDataPowerConsumption = W(NaN);
43 | W transmitterIdlePowerConsumption = W(NaN);
44 | W transmitterTransmittingPowerConsumption = W(NaN);
45 | W transmitterTransmittingPreamblePowerConsumption = W(NaN);
46 | W transmitterTransmittingHeaderPowerConsumption = W(NaN);
47 | W transmitterTransmittingDataPowerConsumption = W(NaN);
48 |
49 | // environment
50 | IRadio *radio = nullptr; // TODO handle multiple ethernet interfaces
51 |
52 | // state
53 | W powerConsumption = W(NaN);
54 |
55 | public:
56 | static simsignal_t networkPowerConsumptionChangedSignal;
57 |
58 | protected:
59 | virtual int numInitStages() const override { return NUM_INIT_STAGES; }
60 | virtual W computePowerConsumption() const;
61 | virtual void initialize(int stage) override;
62 |
63 | public:
64 | virtual W getPowerConsumption() const {return powerConsumption;}
65 | virtual void receiveSignal(cComponent *source, simsignal_t signal, long value, cObject *details) override;
66 | };
67 |
68 | }
69 | /* namespace ecsnetpp */
70 |
71 | #endif /* POWER_CONSUMER_STREAMINGENERGYCONSUMER_H_ */
72 |
--------------------------------------------------------------------------------
/src/power/consumer/NetworkPowerConsumer.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.power.consumer;
17 |
18 | simple NetworkPowerConsumer
19 | {
20 | parameters:
21 | string energySourceModule;
22 | double cpuPowerConsumptionScalar = default(0);
23 | double offPowerConsumption @unit(W) = default(0mW);
24 | double sleepPowerConsumption @unit(W) = default(1mW);
25 | double switchingPowerConsumption @unit(W) = default(1mW);
26 | double receiverIdlePowerConsumption @unit(W) = default(2mW);
27 | double receiverBusyPowerConsumption @unit(W) = default(5mW);
28 | double receiverReceivingPowerConsumption @unit(W) = default(10mW);
29 | double receiverReceivingPreamblePowerConsumption @unit(W) = default(receiverReceivingPowerConsumption);
30 | double receiverReceivingHeaderPowerConsumption @unit(W) = default(receiverReceivingPowerConsumption);
31 | double receiverReceivingDataPowerConsumption @unit(W) = default(receiverReceivingPowerConsumption);
32 | double transmitterIdlePowerConsumption @unit(W) = default(2mW);
33 | double transmitterTransmittingPowerConsumption @unit(W) = default(100mW);
34 | double transmitterTransmittingPreamblePowerConsumption @unit(W) = default(transmitterTransmittingPowerConsumption);
35 | double transmitterTransmittingHeaderPowerConsumption @unit(W) = default(transmitterTransmittingPowerConsumption);
36 | double transmitterTransmittingDataPowerConsumption @unit(W) = default(transmitterTransmittingPowerConsumption);
37 | @display("i=block/cogwheel");
38 | @signal[networkPowerConsumptionChanged](type=double);
39 | @statistic[networkPowerConsumption](title="Wireless Power consumption"; source=networkPowerConsumptionChanged; record=vector; interpolationmode=sample-hold);
40 | @class(NetworkPowerConsumer);
41 | }
42 |
--------------------------------------------------------------------------------
/src/power/consumer/package.ned:
--------------------------------------------------------------------------------
1 | package ecsnetpp.power.consumer;
2 |
3 | @namespace(ecsnetpp);
4 | @license(LGPL);
5 |
--------------------------------------------------------------------------------
/src/power/package.ned:
--------------------------------------------------------------------------------
1 | package ecsnetpp.power;
2 |
3 | @namespace(ecsnetpp);
4 | @license(LGPL);
5 |
--------------------------------------------------------------------------------
/src/power/storage/IdealNodeEnergyStorage.h:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) OpenSim Ltd.
3 | //
4 | // This program is free software; you can redistribute it and/or
5 | // modify it under the terms of the GNU Lesser General Public License
6 | // as published by the Free Software Foundation; either version 2
7 | // of the License, or (at your option) any later version.
8 | //
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with this program; if not, see .
16 | //
17 |
18 | #ifndef POWER_STORAGE_IDEALNODEENERGYSTORAGE_H
19 | #define POWER_STORAGE_IDEALNODEENERGYSTORAGE_H
20 |
21 | #include "inet/common/Units.h"
22 | #include "inet/common/Units.h"
23 | #include "inet/common/INETMath.h"
24 | #include "omnetpp.h"
25 | #include "../../common/SimulationController.h"
26 |
27 | using namespace inet;
28 | using namespace inet::math;
29 | using namespace inet::units::values;
30 | using namespace omnetpp;
31 |
32 | namespace ecsnetpp {
33 |
34 |
35 | class IdealNodeEnergyStorage : public cSimpleModule, public cListener
36 | {
37 | protected:
38 | /**
39 | * The nominal capacity is in the range [0, +infinity).
40 | */
41 | W idlePowerConsumption = W(0);
42 | J nominalCapacity = J(NaN);
43 | long cores = 1;
44 |
45 | /**
46 | * The residual capacity is in the range [0, nominalCapacity].
47 | */
48 | J residualCapacity = J(NaN);
49 | J energyBalance = J(NaN);
50 | J cpuEnergyConsumption = J(NAN);
51 | J networkEnergyConsumption = J(NAN);
52 | J totalEnergyConsumption = J(0);
53 | W totalPowerConsumption = W(0);
54 | W totalIdlePowerConsumption = W(0);
55 | // J _energyConsumption = J(0);
56 | cModule *networkNode = nullptr;
57 | std::map lastCPUEnergyBalanceUpdateMap;
58 | simtime_t lastCPUEnergyBalanceUpdate = -1;
59 | simtime_t lastWirelessEnergyBalanceUpdate = -1;
60 | simtime_t lastlastWirelessEnergyBalanceUpdate = -1;
61 | simtime_t startTime = -1;
62 | simtime_t firstCpuUse = -1;
63 | simtime_t lastCpuUse = -1;
64 | simtime_t edgeProcessingTime = 0;
65 | SimulationController *commonSimController;
66 |
67 | public:
68 | static simsignal_t energyConsumptionChangedSignal;
69 | static simsignal_t idleEnergyConsumptionChangedSignal;
70 | static simsignal_t powerConsumptionChangedSignal;
71 | // static simsignal_t idlePowerConsumptionChangedSignal;
72 | static simsignal_t cpuEnergyConsumptionChangedSignal;
73 | static simsignal_t networkEnergyConsumptionChangedSignal;
74 | static simsignal_t residualCapacityChangedSignal;
75 | static simsignal_t totalEnergySimTimeChangedSignal;
76 |
77 | protected:
78 | virtual void initialize(int stage) override;
79 |
80 | // virtual void updateTotalPowerConsumption();
81 | // virtual void updateTotalPowerGeneration();
82 | // virtual void updateEnergyBalance();
83 | virtual void updateCPUEnergyBalance(W totalPowerConsumption, long index);
84 | virtual void updateWirelessEnergyBalance(W totalPowerConsumption, simtime_t currentTime);
85 | virtual J getTotalEnergy();
86 |
87 | public:
88 | virtual double getNominalEnergyCapacity() const { return double(INFINITY); }
89 | virtual double getResidualEnergyCapacity() const { return double(INFINITY); }
90 | virtual void receiveSignal(cComponent *source, simsignal_t signal, double value, cObject *details) override;
91 |
92 | };
93 |
94 | }
95 |
96 | #endif // ifndef __INET_IDEALEPENERGYSTORAGE_H
97 |
98 |
--------------------------------------------------------------------------------
/src/power/storage/IdealNodeEnergyStorage.ned:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (C) OpenSim Ltd.
3 | //
4 | // This program is free software; you can redistribute it and/or
5 | // modify it under the terms of the GNU General Public License
6 | // as published by the Free Software Foundation; either version 2
7 | // of the License, or (at your option) any later version.
8 | //
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program; if not, see .
16 | //
17 |
18 | package ecsnetpp.power.storage;
19 |
20 | import inet.power.base.EpEnergyStorageBase;
21 |
22 | //
23 | // This energy storage model stores an infinite amount of energy. It can provide
24 | // energy for any number of consumers, and it can absorb energy from any number
25 | // of generators. The ideal energy storage never gets completely charged or
26 | // depleted. This module is primarily useful for testing energy consumer and
27 | // energy generator models. See the base module for signals and statistics.
28 | //
29 | // @author Levente Meszaros
30 | //
31 | simple IdealNodeEnergyStorage
32 | {
33 | parameters:
34 | double idlePowerConsumption @unit(W) = default(0W);
35 | double nominalCapacity @unit(J); // the maximum amount of energy stored
36 | double initialCapacity @unit(J) = default(nominalCapacity); // the initially stored amount of energy
37 | @signal[energyConsumptionChanged](type=double);
38 | @signal[powerConsumptionChanged](type=double);
39 | @signal[idleEnergyConsumptionChanged](type=double);
40 | // @signal[idlePowerConsumptionChanged](type=double);
41 | @signal[cpuEnergyConsumptionChanged](type=double);
42 | @signal[networkEnergyConsumptionChanged](type=double);
43 | @signal[residualCapacityChanged](type=double);
44 | @signal[totalEnergySimTimeChanged](type=double);
45 | @statistic[energyConsumption](title="Total energy consumption"; unit=J; source=energyConsumptionChanged; record=last; interpolationmode=sample-hold);
46 | @statistic[powerConsumption](title="Total power consumption"; unit=W; source=powerConsumptionChanged; record=last; interpolationmode=sample-hold);
47 | @statistic[idleEnergyConsumption](title="Idle energy consumption"; unit=J; source=idleEnergyConsumptionChanged; record=last; interpolationmode=sample-hold);
48 | // @statistic[idlePowerConsumption](title="Idle power consumption"; unit=W; source=idlePowerConsumptionChanged; record=last; interpolationmode=sample-hold);
49 | @statistic[cpuEnergyConsumption](title="CPU energy consumption"; source=cpuEnergyConsumptionChanged; record=vector,last; interpolationmode=sample-hold);
50 | @statistic[networkEnergyConsumption](title="Network energy consumption"; source=networkEnergyConsumptionChanged; record=vector,last; interpolationmode=sample-hold);
51 | @statistic[residualCapacity](title="Residual Capacity"; source=residualCapacityChanged; record=vector; interpolationmode=sample-hold);
52 | @statistic[totalEnergySimTime](title="Total Energy sim time"; source=totalEnergySimTimeChanged; record=last; interpolationmode=sample-hold);
53 |
54 | @class(IdealNodeEnergyStorage);
55 | }
56 |
--------------------------------------------------------------------------------
/src/stask/Acker.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * ConsoleSink.cc
3 | *
4 | * Created on: Sep 26, 2017
5 | * Author: gayashan
6 | */
7 |
8 | #include "omnetpp.h"
9 | #include "../msg/Ack_m.h"
10 |
11 | using namespace omnetpp;
12 |
13 | namespace ecsnetpp {
14 |
15 | class Acker: public cSimpleModule {
16 |
17 | protected:
18 | static simsignal_t rcvdAckSignal;
19 |
20 | protected:
21 | virtual void initialize() override;
22 | virtual void handleMessage(cMessage *msg) override;
23 | };
24 |
25 | Define_Module(Acker);
26 |
27 | simsignal_t Acker::rcvdAckSignal = registerSignal("rcvdAck");
28 |
29 | void Acker::initialize() {
30 | // cMessage *msg = new cMessage("Random Number");
31 | // scheduleAt(simTime() + 1, msg);
32 | }
33 |
34 | void Acker::handleMessage(cMessage *msg) {
35 | Ack *pk = check_and_cast(msg);
36 | EV << "ACK RCVD from=" << pk->getSender() << " for MSG=" << pk->getAckedMessageId()
37 | << endl;
38 | emit(rcvdAckSignal, pk);
39 | delete msg;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/stask/Acker.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.stask;
17 |
18 | simple Acker
19 | {
20 | parameters:
21 | string name = default("Acker");
22 |
23 | @signal[rcvdAck](type=cPacket);
24 | gates:
25 | input ackerIn;
26 | }
--------------------------------------------------------------------------------
/src/stask/ISTask.cc:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #include "ISTask.h"
17 |
18 | namespace ecsnetpp {
19 |
20 | simsignal_t ISTask::receivedStreamingMsgsSignal = registerSignal("receivedStreamingMsgs");
21 | simsignal_t ISTask::cpuUtilisationSignal = registerSignal("cpuUtilisationSignal");
22 | simsignal_t ISTask::cpuStateChangedSignal = registerSignal("cpuStateChanged");
23 | simsignal_t ISTask::latencySignal = registerSignal("latency");
24 | simsignal_t ISTask::transmissionTimeSignal = registerSignal("transmissionTime");
25 | simsignal_t ISTask::processingTimeSignal = registerSignal("processingTime");
26 | simsignal_t ISTask::edgeProcessingTimeSignal = registerSignal("edgeProcessingTime");
27 |
28 | void ISTask::sendAck(cMessage* msg) {
29 | // send ack
30 | if(ackersEnabled){
31 | Ack* ack = new Ack();
32 | ack->setAckedMessageId(msg->getId());
33 | ack->setSender(getFullPath().c_str());
34 | send(ack, "ackerOut");
35 | }
36 | }
37 |
38 | void ISTask::publishCpuStateChanged(States::CPUState state){
39 | emit(cpuStateChangedSignal, state);
40 | }
41 |
42 | long ISTask::getNextProcessorCoreIndex() {
43 | return myCpuCoreScheduler->getNextCPUCoreIndex();
44 | }
45 |
46 | } /* namespace ecsnetpp */
47 |
--------------------------------------------------------------------------------
/src/stask/ISTask.h:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #ifndef STASK_ISTASK_H_
17 | #define STASK_ISTASK_H_
18 |
19 | #include "omnetpp.h"
20 | #include "../msg/StreamingMessage_m.h"
21 | #include "../msg/Ack_m.h"
22 | #include "../power/States.h"
23 | #include "../cpu/scheduling/ICpuCoreScheduler.h"
24 |
25 | using namespace omnetpp;
26 |
27 | namespace ecsnetpp {
28 |
29 | class ISTask: public cSimpleModule {
30 | public:
31 | static simsignal_t receivedStreamingMsgsSignal;
32 | static simsignal_t cpuUtilisationSignal;
33 | static simsignal_t cpuStateChangedSignal;
34 | static simsignal_t packetGeneratedSignal;
35 | static simsignal_t latencySignal;
36 | static simsignal_t transmissionTimeSignal;
37 | static simsignal_t processingTimeSignal;
38 | static simsignal_t edgeProcessingTimeSignal;
39 |
40 | protected:
41 | const char* mySenders;
42 | const char* mySTaskCategory;
43 | std::vector mySendersList;
44 | long cpuCores;
45 | long lastCPUIndex = 0;
46 | double perCoreFreq;
47 | double processingDelayPerEvent;
48 | double delay;
49 | bool ackersEnabled;
50 | bool isProcessingDelayInCpuCycles;
51 | ICpuCoreScheduler* myCpuCoreScheduler;
52 | protected:
53 | virtual void initialize() {
54 | }
55 | ;
56 | virtual void handleMessage(cMessage *msg) {
57 | }
58 | ;
59 | virtual long getNextProcessorCoreIndex();
60 | virtual void sendAck(cMessage* msg);
61 | virtual void publishCpuStateChanged(States::CPUState state);
62 | };
63 |
64 | } /* namespace ecsnetpp */
65 |
66 | #endif /* STASK_ISTASK_H_ */
67 |
--------------------------------------------------------------------------------
/src/stask/ISTask.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.stask;
17 |
18 | moduleinterface ISTask
19 | {
20 | gates:
21 | inout port[];
22 | output ackerOut;
23 | }
24 |
--------------------------------------------------------------------------------
/src/stask/StreamingOperator.cc:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #include "StreamingOperator.h"
17 |
18 | namespace ecsnetpp {
19 |
20 | Define_Module(StreamingOperator);
21 |
22 | void StreamingOperator::finish() {
23 | cancelAndDelete(timerMsg);
24 | if (!outgoingQueue.isEmpty()) {
25 | outgoingQueue.clear();
26 | }
27 | }
28 |
29 | void StreamingOperator::initialize() {
30 | omnetpp::cModule* submodule = getParentModule()->getSubmodule("cpuCoreScheduler");
31 | myCpuCoreScheduler = check_and_cast(submodule);
32 | ackersEnabled = getAncestorPar("ackersEnabled").boolValue();
33 | perCoreFreq = getAncestorPar("perCoreFreq").doubleValue();
34 | isProcessingDelayInCpuCycles = par("isProcessingDelayInCpuCycles").boolValue();
35 | // if (isProcessingDelayInCpuCycles) {
36 | // cyclesPerEvent = par("cyclesPerEvent").doubleValue();
37 | // } else {
38 | processingDelayPerEvent = par("processingDelayPerEvent").doubleValue();
39 | // }
40 |
41 | cpuCores = getAncestorPar("cores").longValue();
42 | if (cpuCores < 1) {
43 | throw new cRuntimeError("Number of CPU Cores is not set.");
44 | }
45 |
46 | isOperatorSelectivityDistributed = par("isOperatorSelectivityDistributed").boolValue();
47 | if(!isOperatorSelectivityDistributed){
48 | selectivityRatio = par("selectivityRatio").doubleValue();
49 | selectivityWindowLength = 0;
50 | if (selectivityRatio > 0) {
51 | selectivityWindowLength = std::lround(1 / selectivityRatio);
52 | }
53 | } else {
54 | myOperatorSelectivityDistributionModuleName = par("myOperatorSelectivityDistributionModuleName").stringValue();
55 | cModule* submodule = getParentModule()->getSubmodule(myOperatorSelectivityDistributionModuleName);
56 |
57 | myOperatorSelectivityDistributionModule = check_and_cast(submodule);
58 | }
59 |
60 | isOperatorProductivityDistributed = par("isOperatorProductivityDistributed").boolValue();
61 | if (!isOperatorProductivityDistributed) {
62 | productivityRatio = par("productivityRatio").doubleValue();
63 | } else {
64 | myOperatorProductivityDistributionModuleName = par("myOperatorProductivityDistributionModuleName").stringValue();
65 | cModule* submodule = getParentModule()->getSubmodule(myOperatorProductivityDistributionModuleName);
66 |
67 | myOperatorProductivityDistributionModule = check_and_cast(submodule);
68 | }
69 |
70 | mySenders = par("mySenders").stringValue();
71 | mySTaskCategory = par("mySTaskCategory").stringValue();
72 | lastCPUIndex = 0;
73 | selectivityWindowCount = 0;
74 |
75 | timerMsg = new cMessage();
76 | timerMsg->setKind(2);
77 | // calculateDelay();
78 | }
79 |
80 | void StreamingOperator::handleMessage(cMessage *msg) {
81 | if (msg->arrivedOn("fromCPU")) {
82 | nextToSend = check_and_cast(msg);
83 | for (int i = 0; i < gateSize("outgoingStream"); i++) {
84 | send(nextToSend->dup(), "outgoingStream", i);
85 | }
86 | // sendAck(nextToSend);
87 | delete nextToSend;
88 | } else if (msg->arrivedOn("incomingStream")) {
89 | StreamingMessage *msgToSend = check_and_cast(msg);
90 | double outgoingMsgSize = msgToSend->getBitLength() * getProductivityRatio();
91 | msgToSend->setBitLength(outgoingMsgSize);
92 | msgToSend->setSender(mySTaskCategory);
93 |
94 | msgToSend->setIsProcessingDelayInCyclesPerEvent(isProcessingDelayInCpuCycles);
95 | msgToSend->setProcessingDelayPerEvent(processingDelayPerEvent);
96 |
97 | double _selectivityRatio = getSelectivityRatio();
98 | msgToSend->setSelectivityRatio(_selectivityRatio);
99 | double _selectivityWindowLength = getSelectivityWindowLength();
100 | long nextInLine = getNextProcessorCoreIndex();
101 | cModule *cpuCore = getParentModule()->getSubmodule("cpuCore", nextInLine);
102 | if(_selectivityRatio < 1) {
103 | selectivityWindow.insert(msgToSend);
104 | if (selectivityWindow.getLength() >= _selectivityWindowLength) {
105 | nextToSend = check_and_cast(
106 | selectivityWindow.pop());
107 | sendDirect(nextToSend, cpuCore, "incomingBus");
108 | if (!selectivityWindow.isEmpty()) {
109 | if (selectivityWindow.getLength() < _selectivityWindowLength) {
110 | selectivityWindow.clear();
111 | } else {
112 | for (int i = 0; i < _selectivityWindowLength - 1; i++) {
113 | selectivityWindow.pop();
114 | }
115 | }
116 | }
117 | }
118 | } else{
119 | sendDirect(msgToSend, cpuCore, "incomingBus");
120 | }
121 | }
122 | // if (msg->isSelfMessage()) {
123 | // if (msg->getKind() == 2) {
124 | //// std::cout << "sending new msg" << endl;
125 | // nextToSend = check_and_cast(
126 | // outgoingQueue.pop());
127 | // if (selectivityRatio >= 1) {
128 | // int _sratio = std::lround(selectivityRatio); // get the rounded value of the selectivity
129 | // for (int j = 0; j < _sratio; j++) { // send a msg for each incoming msg
130 | // for (int i = 0; i < gateSize("outgoingStream"); i++) {
131 | // send(nextToSend->dup(), "outgoingStream", i);
132 | // }
133 | // sendAck(nextToSend);
134 | // }
135 | // delete nextToSend;
136 | // } else {
137 | // // If selectivity < 1, then hold the message in a queue
138 | // // until the queue length = 1/selectivity. Then pop the first
139 | // // msg in the queue and send it to the downstream.
140 | // // Clear the queue afterwards and wait for the next event.
141 | // selectivityWindow.insert(nextToSend);
142 | // if(selectivityWindow.getLength() >= selectivityWindowLength){
143 | // nextToSend = check_and_cast(selectivityWindow.pop());
144 | // for (int i = 0; i < gateSize("outgoingStream"); i++) {
145 | // send(nextToSend->dup(), "outgoingStream", i);
146 | // }
147 | // if (!selectivityWindow.isEmpty()) {
148 | // selectivityWindow.clear();
149 | // }
150 | // sendAck(nextToSend);
151 | // delete nextToSend;
152 | // }
153 | // }
154 | // } else {
155 | // // unknown msg
156 | // delete msg;
157 | // }
158 | // publishCpuStateChanged(States::CPU_IDLE);
159 | // } else { // not self message
160 | // StreamingMessage *msgToSend = check_and_cast(msg);
161 | // const char* sender = msgToSend->getSender();
162 | // if (strstr(mySenders, sender) == NULL) { // check if the intended receiver is the current node
163 | // delete msg;
164 | // } else {
165 | // publishCpuStateChanged(States::CPU_BUSY);
166 | // double outgoingMsgSize = msgToSend->getSize() * sizeIncreaseRatio;
167 | // msgToSend->setSize(outgoingMsgSize);
168 | // msgToSend->setSender(mySTaskCategory);
169 | // msgToSend->setCyclesPerEvent(cyclesPerEvent);
170 | // outgoingQueue.insert(msgToSend);
171 | //
172 | // if (!timerMsg->isScheduled()) {
173 | // cancelAndDelete(timerMsg);
174 | // }
175 | //
176 | // timerMsg = new cMessage();
177 | // timerMsg->setKind(2);
178 | // scheduleAt(simTime() + delay, timerMsg);
179 | // }
180 | // }
181 | }
182 |
183 | double StreamingOperator::getSelectivityRatio(){
184 | if (isOperatorSelectivityDistributed) {
185 | return myOperatorSelectivityDistributionModule->getSelectivityRatio();
186 | }
187 | return selectivityRatio;
188 | }
189 |
190 | double StreamingOperator::getSelectivityWindowLength(){
191 | if (isOperatorSelectivityDistributed) {
192 | return myOperatorSelectivityDistributionModule->getSelectivityWindowLength();
193 | }
194 | return selectivityWindowLength;
195 | }
196 |
197 | double StreamingOperator::getProductivityRatio(){
198 | if (isOperatorProductivityDistributed) {
199 | return myOperatorProductivityDistributionModule->getProductivityRatio();
200 | }
201 | return productivityRatio;
202 | }
203 |
204 | } /* namespace ecsnetpp */
205 |
--------------------------------------------------------------------------------
/src/stask/StreamingOperator.h:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #ifndef STASK_STREAMINGOPERATOR_H_
17 | #define STASK_STREAMINGOPERATOR_H_
18 |
19 | #include "omnetpp.h"
20 | #include "../msg/StreamingMessage_m.h"
21 | #include "ISTask.h"
22 | #include "../model/operator/selectivity/IOperatorSelectivityDistribution.h"
23 | #include "../model/operator/productivity/IOperatorProductivityDistribution.h"
24 |
25 | using namespace omnetpp;
26 |
27 | namespace ecsnetpp {
28 |
29 | class StreamingOperator : public ISTask{
30 | private:
31 | int selectivityWindowLength;
32 | int selectivityWindowCount;
33 | protected:
34 | cQueue outgoingQueue;
35 | cQueue selectivityWindow;
36 | cMessage *timerMsg = nullptr;
37 | StreamingMessage* nextToSend;
38 | double selectivityRatio = 0; // number of outgoing messages to be generated per each incoming message
39 | double productivityRatio = 0; // sizeof(outgoing msg)/sizeof(incoming msg)
40 | const char* myOperatorSelectivityDistributionModuleName;
41 | const char* myOperatorProductivityDistributionModuleName;
42 | bool isOperatorSelectivityDistributed = false;
43 | bool isOperatorProductivityDistributed = false;
44 | IOperatorSelectivityDistribution* myOperatorSelectivityDistributionModule;
45 | IOperatorProductivityDistribution* myOperatorProductivityDistributionModule;
46 | public:
47 | //// StreamingTask();
48 | // virtual ~StreamingOperator();
49 | protected:
50 | virtual void initialize() override;
51 | virtual void handleMessage(cMessage *msg) override;
52 | virtual void finish() override;
53 | virtual double getSelectivityRatio();
54 | virtual double getSelectivityWindowLength();
55 | virtual double getProductivityRatio();
56 | };
57 |
58 | } /* namespace ecsnetpp */
59 |
60 | #endif /* STASK_STREAMINGOPERATOR_H_ */
61 |
--------------------------------------------------------------------------------
/src/stask/StreamingOperator.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.stask;
17 |
18 | simple StreamingOperator like ISTask
19 | {
20 | parameters:
21 | string name = default("StreamingTask");
22 | @signal[cpuStateChanged](type=long);
23 | gates:
24 | inout port[];
25 | input incomingStream[];
26 | output outgoingStream[];
27 | input fromCPU;
28 | output toCPU;
29 | output ackerOut;
30 | }
31 |
--------------------------------------------------------------------------------
/src/stask/StreamingSink.cc:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #include "StreamingSink.h"
17 |
18 | namespace ecsnetpp {
19 |
20 | Define_Module(StreamingSink);
21 |
22 | void StreamingSink::initialize() {
23 | omnetpp::cModule* submodule = getParentModule()->getSubmodule("cpuCoreScheduler");
24 | myCpuCoreScheduler = check_and_cast(submodule);
25 | ackersEnabled = getAncestorPar("ackersEnabled").boolValue();
26 | perCoreFreq = getAncestorPar("perCoreFreq").doubleValue();
27 | // if (isProcessingDelayInCpuCycles) {
28 | // cyclesPerEvent = par("cyclesPerEvent").doubleValue();
29 | // } else {
30 | processingDelayPerEvent = par("processingDelayPerEvent").doubleValue();
31 | // }
32 | mySenders = par("mySenders").stringValue();
33 | mySTaskCategory = par("mySTaskCategory").stringValue();
34 | lastCPUIndex = 0;
35 | cpuCores = getAncestorPar("cores").longValue();
36 | if (cpuCores < 1) {
37 | throw new cRuntimeError("Number of CPU Cores is not set.");
38 | }
39 | // calculateDelay();
40 | }
41 |
42 | void StreamingSink::handleMessage(cMessage *msg) {
43 | if (msg->arrivedOn("fromCPU")) {
44 | StreamingMessage *pk = check_and_cast(msg);
45 | double _networkDelay = pk->getNetworkDelay();
46 | double _processingDelay = pk->getProcessingDelay();
47 | emit(transmissionTimeSignal, _networkDelay);
48 | emit(processingTimeSignal, _processingDelay);
49 | // const omnetpp::SimTime _latency = simTime() - pk->getStartTime();
50 | emit(latencySignal, _networkDelay + _processingDelay);
51 | emit(edgeProcessingTimeSignal, pk->getEdgeProcessingDelay());
52 | emit(receivedStreamingMsgsSignal, pk);
53 | // std::cout << " CPU proc delay: " << pk->getEdgeProcessingDelay() << " : " << pk->getProcessingDelay() << endl;
54 | // std::cout << "##Finished Processing. Msg size (Bytes): " << pk->getByteLength() << " (Bits): " << pk->getBitLength() << endl;
55 |
56 | // sendAck(msg);
57 | delete msg;
58 | } else if (msg->arrivedOn("incomingStream")) {
59 | StreamingMessage *msgToSend = check_and_cast(msg);
60 | msgToSend->setSender(mySTaskCategory);
61 |
62 | msgToSend->setIsProcessingDelayInCyclesPerEvent(isProcessingDelayInCpuCycles);
63 | msgToSend->setProcessingDelayPerEvent(processingDelayPerEvent);
64 |
65 | msgToSend->setSelectivityRatio(1);
66 | long nextInLine = getNextProcessorCoreIndex();
67 | cModule *cpuCore = getParentModule()->getSubmodule("cpuCore", nextInLine);
68 | sendDirect(msgToSend, cpuCore, "incomingBus");
69 | }
70 | // StreamingMessage *pk = check_and_cast(msg);
71 | // const char* sender = pk->getSender();
72 | // if (strstr(mySenders, sender) == NULL) {
73 | // delete msg;
74 | // } else {
75 | // publishCpuStateChanged(States::CPU_BUSY);
76 | // emit(rcvdPkSignal, pk);
77 | // sendAck(msg);
78 | // delete msg;
79 | //
80 | // publishCpuStateChanged(States::CPU_IDLE);
81 | // }
82 | }
83 | } /* namespace ecsnetpp */
84 |
--------------------------------------------------------------------------------
/src/stask/StreamingSink.h:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #ifndef STASK_STREAMINGSINK_H_
17 | #define STASK_STREAMINGSINK_H_
18 |
19 | #include "omnetpp.h"
20 | #include "../msg/StreamingMessage_m.h"
21 | #include "ISTask.h"
22 |
23 | using namespace omnetpp;
24 |
25 | namespace ecsnetpp {
26 |
27 | class StreamingSink : public ISTask{
28 | protected:
29 | virtual void initialize() override;
30 | virtual void handleMessage(cMessage *msg) override;
31 |
32 | };
33 |
34 | } /* namespace ecsnetpp */
35 |
36 | #endif /* STASK_STREAMINGSINK_H_ */
37 |
--------------------------------------------------------------------------------
/src/stask/StreamingSink.ned:
--------------------------------------------------------------------------------
1 | // This program is free software: you can redistribute it and/or modify
2 | // it under the terms of the GNU Lesser General Public License as published by
3 | // the Free Software Foundation, either version 3 of the License, or
4 | // (at your option) any later version.
5 | //
6 | // This program is distributed in the hope that it will be useful,
7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | // GNU Lesser General Public License for more details.
10 | //
11 | // You should have received a copy of the GNU Lesser General Public License
12 | // along with this program. If not, see http://www.gnu.org/licenses/.
13 | //
14 |
15 | package ecsnetpp.stask;
16 |
17 | simple StreamingSink like ISTask
18 | {
19 | parameters:
20 | string name = default("StreamingSink");
21 | @signal[cpuStateChanged](type=long);
22 | @signal[receivedStreamingMsgs](type=cPacket);
23 | @signal[latency](type=double);
24 | @signal[transmissionTime](type=double);
25 | @signal[processingTime](type=double);
26 | @signal[edgeProcessingTime](type=double);
27 | @statistic[rcvdStreamingMsgsStat](title="packets received"; source=receivedStreamingMsgs; record=count,"sum(packetBytes)","vector(packetBytes)"; interpolationmode=none);
28 | @statistic[throughput](title="throughput"; unit=bps; source="throughput(receivedStreamingMsgs)"; record=vector);
29 | @statistic[rcvdStreamingMsgsCount](title="Streaming Msg Count"; source=receivedStreamingMsgs; record=count);
30 | @statistic[endToEndDelay](title="end-to-end delay"; source="messageAge(receivedStreamingMsgs)"; unit=s; record=min,max,mean,stats,histogram,vector; interpolationmode=sample-hold);
31 | @statistic[receivedStreamingMsgsSeqNo](title="received packet sequence number"; source="appPkSeqNo(receivedStreamingMsgs)"; record=vector; interpolationmode=none);
32 |
33 | gates:
34 | inout port[];
35 | input incomingStream[];
36 | output outgoingStream[];
37 | input fromCPU;
38 | output toCPU;
39 | output ackerOut;
40 | }
41 |
--------------------------------------------------------------------------------
/src/stask/StreamingSource.cc:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #include "StreamingSource.h"
17 |
18 | namespace ecsnetpp {
19 |
20 | Define_Module(StreamingSource);
21 |
22 | simsignal_t ISTask::packetGeneratedSignal = registerSignal("packetGenerated");
23 |
24 | StreamingSource::~StreamingSource() {
25 | cancelAndDelete(timerMsg);
26 | }
27 |
28 | void StreamingSource::initialize() {
29 | perCoreFreq = getAncestorPar("perCoreFreq").doubleValue();
30 | omnetpp::cModule* submodule = getParentModule()->getSubmodule("cpuCoreScheduler");
31 | myCpuCoreScheduler = check_and_cast(submodule);
32 | // if (isProcessingDelayInCpuCycles) {
33 | // cyclesPerEvent = par("cyclesPerEvent").doubleValue();
34 | // } else {
35 | processingDelayPerEvent = par("processingDelayPerEvent").doubleValue();
36 | // }
37 | // calculateDelay();
38 | lastCPUIndex = 0;
39 | cpuCores = getAncestorPar("cores").longValue();
40 | if (cpuCores < 1) {
41 | throw new cRuntimeError("Number of CPU Cores is not set.");
42 | }
43 | mySTaskCategory = par("mySTaskCategory").stringValue();
44 |
45 | isSourceMsgSizeDistributed = par("isSourceMsgSizeDistributed").boolValue();
46 | if (!isSourceMsgSizeDistributed) {
47 | msgSize = par("msgSize").doubleValue();
48 | } else {
49 | mySourceMsgSizeDistributionModuleName = par("mySourceMsgSizeDistributionModuleName").stringValue();
50 | omnetpp::cModule* submodule = getParentModule()->getSubmodule(mySourceMsgSizeDistributionModuleName);
51 |
52 | mySourceMsgSizeDistributionModule = check_and_cast(submodule);
53 | }
54 |
55 | isSourceEvRateDistributed = par("isSourceEvRateDistributed").boolValue();
56 | if (!isSourceEvRateDistributed) {
57 | eventRate = par("eventRate").doubleValue(); //evs per second
58 | if (eventRate != 0) {
59 | msgDelay = 1 / eventRate;
60 | } else {
61 | throw cRuntimeError("Event rate is not set for the source : %s",
62 | getFullPath().c_str());
63 | }
64 | } else {
65 | mySourceEvRateDistributionModuleName = par("mySourceEvRateDistributionModuleName").stringValue();
66 | omnetpp::cModule* submodule = getParentModule()->getSubmodule(mySourceEvRateDistributionModuleName);
67 |
68 | mySourceEvRateDistributionModule = check_and_cast(submodule);
69 | }
70 |
71 | timerMsg = new cMessage("BEGIN");
72 | commonSimController = check_and_cast(
73 | getParentModule()->getParentModule()->getModuleByPath(
74 | ".simController"));
75 | scheduleAt(simTime() + getMessageDelay(), timerMsg);
76 | }
77 |
78 | void StreamingSource::handleMessage(cMessage *msg) {
79 | // publishCpuStateChanged(States::CPU_BUSY);
80 |
81 | if (msg->isSelfMessage()) {
82 | if (!commonSimController->getStopEventGeneration()) {
83 | StreamingMessage *sourceMsg = new StreamingMessage();
84 | sourceMsg->setBitLength(getMessageSize());
85 |
86 | sourceMsg->setIsProcessingDelayInCyclesPerEvent(isProcessingDelayInCpuCycles);
87 | sourceMsg->setProcessingDelayPerEvent(processingDelayPerEvent);
88 |
89 | // if (isProcessingDelayInCpuCycles){
90 | // sourceMsg->setIsProcessingDelayInCyclesPerEvent(true);
91 | // sourceMsg->setProcessingDelayPerEvent(cyclesPerEvent);
92 | // } else {
93 | // sourceMsg->setIsProcessingDelayInCyclesPerEvent(false);
94 | // sourceMsg->setProcessingDelayPerEvent(processingDelayPerEvent);
95 | // }
96 | sourceMsg->setStartTime(simTime());
97 | sourceMsg->setSender(mySTaskCategory);
98 | sourceMsg->setSelectivityRatio(1);
99 | sourceMsg->setNetworkDelay(0);
100 | sourceMsg->setProcessingDelay(0);
101 | sourceMsg->setEdgeProcessingDelay(0);
102 | long nextInLine = getNextProcessorCoreIndex();
103 | cModule *cpuCore = getParentModule()->getSubmodule("cpuCore",
104 | nextInLine);
105 | // send(sourceMsg,"toCPU");
106 | sendDirect(sourceMsg, cpuCore, "incomingBus");
107 | cancelEvent(timerMsg);
108 | scheduleAt(simTime() + getMessageDelay(), timerMsg);
109 | }
110 | } else if (msg->arrivedOn("fromCPU")) {
111 | StreamingMessage *sourceMsg = check_and_cast(msg);
112 | emit(packetGeneratedSignal, 1, getParentModule());
113 | for (int i = 0; i < gateSize("outgoingStream"); i++) {
114 | send(sourceMsg->dup(), "outgoingStream", i);
115 | }
116 | } else {
117 | delete msg;
118 | }
119 |
120 | // publishCpuStateChanged(States::CPU_IDLE);
121 | }
122 |
123 | double StreamingSource::getMessageDelay() {
124 | if (isSourceEvRateDistributed) {
125 | return mySourceEvRateDistributionModule->getMessageDelay();
126 | }
127 | return msgDelay;
128 | }
129 |
130 | double StreamingSource::getMessageSize() {
131 | if (isSourceMsgSizeDistributed) {
132 | return mySourceMsgSizeDistributionModule->getMsgSize();
133 | }
134 | return msgSize;
135 | }
136 | } /* namespace ecsnetpp */
137 |
--------------------------------------------------------------------------------
/src/stask/StreamingSource.h:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | #ifndef STASK_STREAMINGSOURCE_H_
17 | #define STASK_STREAMINGSOURCE_H_
18 |
19 | #include "omnetpp.h"
20 | #include "../msg/StreamingMessage_m.h"
21 | #include "ISTask.h"
22 | #include "../common/SimulationController.h"
23 | #include "../model/source/eventrate/ISourceEventRateDistribution.h"
24 | #include "../model/source/msgsize/IMessageSizeDistribution.h"
25 |
26 | using namespace omnetpp;
27 |
28 | namespace ecsnetpp {
29 |
30 | class StreamingSource: public ISTask {
31 | protected:
32 | cQueue outgoingQueue;
33 | cMessage *timerMsg = nullptr;
34 | double msgSize = 0;
35 | double eventRate = 0;
36 | double msgDelay = 0;
37 | bool isSourceEvRateDistributed = false;
38 | bool isSourceMsgSizeDistributed = false;
39 | const char* mySourceEvRateDistributionModuleName;
40 | const char* mySourceMsgSizeDistributionModuleName;
41 | SimulationController *commonSimController;
42 | ISourceEventRateDistribution* mySourceEvRateDistributionModule;
43 | IMessageSizeDistribution* mySourceMsgSizeDistributionModule;
44 | public:
45 | virtual ~StreamingSource();
46 | protected:
47 | virtual void initialize() override;
48 | virtual void handleMessage(cMessage *msg) override;
49 | virtual double getMessageDelay();
50 | virtual double getMessageSize();
51 | };
52 |
53 | } /* namespace ecsnetpp */
54 |
55 | #endif /* STASK_STREAMINGSOURCE_H_ */
56 |
--------------------------------------------------------------------------------
/src/stask/StreamingSource.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.stask;
17 |
18 | simple StreamingSource like ISTask
19 | {
20 | parameters:
21 | string name = default("StreamingSource");
22 | @signal[cpuStateChanged](type=long);
23 | @signal[packetGenerated](type=long);
24 | gates:
25 | inout port[];
26 | input incomingStream[];
27 | output outgoingStream[];
28 | input fromCPU;
29 | output toCPU;
30 | output ackerOut;
31 | }
--------------------------------------------------------------------------------
/src/stask/StreamingSupervisor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Supervisor.h
3 | *
4 | * Created on: Oct 24, 2017
5 | * Author: gayashan
6 | */
7 |
8 | #ifndef STASK_STREAMINGSUPERVISOR_H_
9 | #define STASK_STREAMINGSUPERVISOR_H_
10 |
11 | #include "omnetpp.h"
12 | #include "inet/transportlayer/contract/udp/UDPSocket.h"
13 | #include "inet/transportlayer/contract/tcp/TCPSocket.h"
14 | #include "inet/transportlayer/contract/tcp/TCPSocketMap.h"
15 |
16 | using namespace omnetpp;
17 |
18 | namespace ecsnetpp {
19 |
20 | class StreamingSupervisor: public cSimpleModule , public inet::TCPSocket::CallbackInterface{
21 |
22 | private:
23 | const char* cloudAddress;
24 | bool joinMulticastGroup;
25 | bool ackersEnabled;
26 | bool checkpointsEnabled;
27 | bool hasUdp;
28 | bool hasTcp;
29 | inet::UDPSocket udpSocket;
30 | inet::TCPSocket tcpSocket;
31 | inet::TCPSocket serverSocket;
32 | inet::TCPSocketMap tcpSocketMap;
33 | cMessage *selfMsg = nullptr;
34 | cMessage *bindMsg = nullptr;
35 | cMessage *joinMCastMsg = nullptr;
36 | std::map destinationSocketMap;
37 | std::map> senderStaskCategoryToDownstreamNodeMap;
38 | std::map> senderStaskCategoryToDownstreamNodeIPMap;
39 |
40 | simtime_t startTime = -1;
41 | int count = 0;
42 | void processSelfMessage();
43 | void processUDPMessage(omnetpp::cMessage* msg);
44 | void processTCPMessage(omnetpp::cMessage* msg);
45 |
46 | public:
47 | static simsignal_t sentPkSize;
48 | static simsignal_t completedMIPS;
49 | protected:
50 | virtual void initialize() override;
51 | virtual void handleMessage(cMessage *msg) override;
52 | void processUDPPacket(cMessage *msg);
53 | void processUDPError(cMessage *error);
54 | public:
55 | virtual ~StreamingSupervisor();
56 | virtual void addSTaskCategoryToDownstreamNodeMapping(
57 | std::string senderSTaskCategory,
58 | std::string downstreamNodeFullPath);
59 | virtual void addSTaskCategoryToDownstreamNodeMapping(
60 | std::string senderSTaskCategory,
61 | std::vector downstreamNodeFullPaths);
62 | virtual void resolveDownstreamNodeIPs();
63 | virtual void socketDataArrived(int connId, void *yourPtr, cPacket *msg, bool urgent) override;
64 | virtual void socketFailure(int connId, void *yourPtr, int code) override;
65 | };
66 |
67 | }
68 |
69 | #endif /* STASK_STREAMINGSUPERVISOR_H_ */
70 |
--------------------------------------------------------------------------------
/src/stask/StreamingSupervisor.ned:
--------------------------------------------------------------------------------
1 | //
2 | // This program is free software: you can redistribute it and/or modify
3 | // it under the terms of the GNU Lesser General Public License as published by
4 | // the Free Software Foundation, either version 3 of the License, or
5 | // (at your option) any later version.
6 | //
7 | // This program is distributed in the hope that it will be useful,
8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | // GNU Lesser General Public License for more details.
11 | //
12 | // You should have received a copy of the GNU Lesser General Public License
13 | // along with this program. If not, see http://www.gnu.org/licenses/.
14 | //
15 |
16 | package ecsnetpp.stask;
17 |
18 | simple StreamingSupervisor
19 | {
20 | parameters:
21 | string name = default("Supervisor");
22 | bool joinMulticastGroup = default(false);
23 | string dataTransferMode @enum("bytecount","object","bytestream") = default("object");
24 | gates:
25 | input udpIn @labels(UDPControlInfo/up);
26 | output udpOut @labels(UDPControlInfo/down);
27 | input tcpIn @labels(TCPCommand/up);
28 | output tcpOut @labels(TCPCommand/down);
29 | inout supInOut[];
30 | input streamingPortIn[];
31 | output streamingPortOut[];
32 | input sendToAcker[];
33 | output ackerOut[];
34 | input fromCheckpointManager[];
35 | output toCheckpointManager[];
36 | }
37 |
--------------------------------------------------------------------------------
/src/stask/package.ned:
--------------------------------------------------------------------------------
1 | package ecsnetpp.stask;
2 |
3 | @namespace(ecsnetpp);
4 | @license(LGPL);
5 |
--------------------------------------------------------------------------------