├── .cproject ├── .gitignore ├── .nedexclusions ├── .nedfolders ├── .oppbuildspec ├── .project ├── Makefile ├── README.md ├── simulations ├── omnetpp.ini ├── package.ned ├── run ├── task_offloading │ ├── antenna.xml │ ├── config.xml │ ├── erlangen.png │ ├── omnetpp.ini │ ├── task_offloading.launchd.xml │ ├── task_offloading.ned │ ├── task_offloading.net.xml │ ├── task_offloading.poly.xml │ ├── task_offloading.rou.xml │ └── task_offloading.sumo.cfg └── veins │ ├── README │ ├── RSUExampleScenario.ned │ ├── antenna.xml │ ├── config.xml │ ├── erlangen.launchd.xml │ ├── erlangen.net.xml │ ├── erlangen.png │ ├── erlangen.poly.xml │ ├── erlangen.rou.xml │ ├── erlangen.sumo.cfg │ ├── omnetpp.ini │ └── run └── src ├── app ├── Task.cc ├── Task.h ├── TaskGenerator.cc ├── TaskGenerator.h ├── TaskGenerator.ned ├── Worker.cc ├── Worker.h ├── Worker.ned ├── loadBalancing │ ├── BusState.cc │ ├── BusState.h │ ├── LoadBalancing.cc │ └── sortingAlgorithm │ │ ├── BaseSorting.cc │ │ ├── BaseSorting.h │ │ ├── ComputationTime.cc │ │ ├── ComputationTime.h │ │ ├── ComputationTime.ned │ │ ├── FIFO.cc │ │ ├── FIFO.h │ │ ├── FIFO.ned │ │ └── ISorting.ned ├── messages │ ├── AckMessage.msg │ ├── AckTimerMessage.msg │ ├── AvailabilityMessage.msg │ ├── ComputationTimerMessage.msg │ ├── DataMessage.msg │ ├── HelpMessage.msg │ ├── LoadBalanceTimerMessage.msg │ ├── ResponseMessage.msg │ └── UpdateAvailabilityMessage.msg ├── messagesHandling │ ├── AvailabilityMessageHandler.cc │ ├── DataMessageHandler.cc │ ├── HelpMessageHandler.cc │ └── ResponseMessageHandler.cc ├── secureProtocol │ ├── SendAgainDataMessage.cc │ └── SendAgainResponseMessage.cc └── vehiclesHandling │ ├── HelperVehicleInfo.cc │ ├── HelperVehicleInfo.h │ └── VehicleHandler.cc ├── package.ned └── task_offloading_dbg /.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore generated files 2 | src/**/*_m.h 3 | src/**/*_m.cc 4 | src/**/Makefile 5 | src/Makefile.vc 6 | /doc/doxy/ 7 | /doc/neddoc/ 8 | *.pcap 9 | *.sca 10 | *.vec 11 | *.vci 12 | *.anf 13 | *.qtenvrc 14 | .settings/ 15 | err/ 16 | src/err 17 | **/simulator_5g_v2x* 18 | **/libsimulator_5g_v2x* 19 | # ignore binary files 20 | out/ 21 | *.so 22 | *.dylib 23 | *.dll 24 | *.a 25 | *.lib 26 | *.exe 27 | *.o 28 | *.obj 29 | *.pdb 30 | *.idb 31 | *.manifest 32 | .tkenvrc 33 | .tkenvlog 34 | *.out 35 | .computed 36 | 37 | # ignore backup and temp files 38 | *.bak 39 | backups 40 | *~ 41 | *.log 42 | 43 | 44 | *.FAILED 45 | *.UPDATED 46 | *.ERROR 47 | ui/com.simulte.configeditor/bin/ 48 | 49 | # ignore result folders 50 | /simulations/gtpNetwork/ResultLteCoreNetwork/ 51 | /simulations/*/results*/ 52 | /simulations/*/*/results*/ 53 | /simulations/*/*/*/results*/ 54 | /simulations/*/scenario*/ 55 | /simulations/*/eval*/ 56 | /simulations/results*/ 57 | /simulations/*/.cmdenv-log 58 | /simulations/.cmdenv-log 59 | *.rt 60 | *.elog 61 | 62 | /simulations/*/*/stats*/ 63 | /simulations/*/*/positions*/ 64 | /simulations/*/*/outLogs*/ 65 | /simulations/*/*/scripts/plots*/ 66 | /simulations/*/*/plots*/ 67 | /simulations/*/*/timeResults*/ 68 | /simulations/*/*/routing*/bkUe?.mrt 69 | /simulations/*/*/routing*/bkUe??.mrt 70 | /simulations/*/*/routing*/bkUe???.mrt 71 | 72 | /emulation/*/results*/ 73 | /emulation/*/plots*/ 74 | 75 | vim files 76 | *.swp 77 | *.swo 78 | .qtenvrc.* 79 | 80 | # files for performance evaluation 81 | *.ipynb 82 | 83 | simulations/results* 84 | -------------------------------------------------------------------------------- /.nedexclusions: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connets/task_offloading/ee1f9916aebdcc5fd3ff039fdc5abf8ff6acebc8/.nedexclusions -------------------------------------------------------------------------------- /.nedfolders: -------------------------------------------------------------------------------- 1 | simulations 2 | src 3 | -------------------------------------------------------------------------------- /.oppbuildspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tirocinio 4 | 5 | 6 | inet4.4 7 | veins-5.2 8 | 9 | 10 | 11 | org.omnetpp.cdt.MakefileBuilder 12 | 13 | 14 | 15 | 16 | org.omnetpp.scave.builder.vectorfileindexer 17 | 18 | 19 | 20 | 21 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 22 | clean,full,incremental, 23 | 24 | 25 | 26 | 27 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 28 | full,incremental, 29 | 30 | 31 | 32 | 33 | 34 | org.eclipse.cdt.core.cnature 35 | org.eclipse.cdt.core.ccnature 36 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 37 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 38 | org.omnetpp.main.omnetppnature 39 | 40 | 41 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: checkmakefiles 2 | cd src && $(MAKE) 3 | 4 | clean: checkmakefiles 5 | cd src && $(MAKE) clean 6 | 7 | cleanall: checkmakefiles 8 | cd src && $(MAKE) MODE=release clean 9 | cd src && $(MAKE) MODE=debug clean 10 | rm -f src/Makefile 11 | 12 | # makefiles: 13 | # cd src && opp_makemake -f --deep 14 | 15 | makefiles: 16 | cd src && opp_makemake -f --deep -O out -KINET_PROJ=../../inet -KVEINS_VEINS_5_2_PROJ=../../veins-veins-5.2 -DINET_IMPORT -DVEINS_IMPORT -I. -I$$\(INET_PROJ\)/src -I$$\(VEINS_VEINS_5_2_PROJ\)/src -Isrc -L$$\(INET_PROJ\)/src -L$$\(VEINS_VEINS_5_2_PROJ\)/src -lINET$$\(D\) -lveins$$\(D\) 17 | 18 | checkmakefiles: 19 | @if [ ! -f src/Makefile ]; then \ 20 | echo; \ 21 | echo '======================================================================='; \ 22 | echo 'src/Makefile does not exist. Please use "make makefiles" to generate it!'; \ 23 | echo '======================================================================='; \ 24 | echo; \ 25 | exit 1; \ 26 | fi 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tirocinio 2 | 3 | ## Obiettivo 4 | Valutazione delle prestazioni di un servizio microcloud di task offloading in vehicular edge computing 5 | 6 | ## Tools utilizzati 7 | - OMNeT++ ([documentation](https://omnetpp.org/documentation/)) 8 | - SUMO ([documentation](https://sumo.dlr.de/docs/)) 9 | 10 | ## Framework utilizzati 11 | - Veins ([documentation](https://veins.car2x.org/documentation/)) 12 | - INET ([documentation](https://inet.omnetpp.org/Introduction.html)) 13 | 14 | ### Riproduzione ambiente di lavoro (in locale) 15 | - Installare/compilare OMNeT++ 16 | - Installare/importare il progetto INET in OMNeT++ 17 | - Installare/importare il progetto Veins in OMNeT++ 18 | - Eseguire build di tutti i progetti 19 | - Importare questo progetto all'interno del workspace 20 | - Eseguire build del progetto 21 | 22 | ### Riproduzione ambiente di lavoro (con Docker) 23 | È stata resa disponibile una versione containerizzata con Docker del progetto, per poterla eseguire: 24 | - Clonare la repo e spostarsi sul branch `main-docker` 25 | - `docker compose build` 26 | - `docker compose up` 27 | 28 | Questi comandi permettono di ricreare l'ambiente di lavoro in Docker ed eseguire la simulazione automaticamente.
29 | I risultati verranno salvati nella cartella locale `simulations/v5_0_Final/results` all'interno del progetto. 30 | 31 | --- 32 | 33 | ***NOTE*** 34 | - I branch `main` e `main-docker` contengono le versioni stabili delle corrispettive versioni in locale e su docker. 35 | - I branch `develop` e `develop-docker` contengono gli ultimi aggiornamenti e le ultime modifiche al progetto. 36 | - Il branch `refactoring` non contiene nuove funzionalità, ma è utilizzato per la manutenzione e rifattorizzazione del codice. 37 | 38 | --- 39 | 40 | @author [Luca Parenti](https://github.com/SuPaRuC)
41 | @supervisor [Christian Quadri](https://github.com/christianquadri) 42 | -------------------------------------------------------------------------------- /simulations/omnetpp.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /simulations/package.ned: -------------------------------------------------------------------------------- 1 | package task_offloading.simulations; 2 | 3 | @license(LGPL); 4 | -------------------------------------------------------------------------------- /simulations/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd `dirname $0` 3 | ../src/tirocinio -n .:../src $* 4 | # for shared lib, use: opp_run -l ../src/tirocinio -n .:../src $* 5 | -------------------------------------------------------------------------------- /simulations/task_offloading/antenna.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /simulations/task_offloading/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /simulations/task_offloading/erlangen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connets/task_offloading/ee1f9916aebdcc5fd3ff039fdc5abf8ff6acebc8/simulations/task_offloading/erlangen.png -------------------------------------------------------------------------------- /simulations/task_offloading/omnetpp.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | cmdenv-express-mode = true 3 | cmdenv-autoflush = true 4 | cmdenv-status-frequency = 1s 5 | **.cmdenv-log-level = info 6 | **.result-recording-modes = all 7 | seed-set = ${repetition} 8 | 9 | image-path = ../../images 10 | 11 | network = task_offloading 12 | 13 | ########################################################## 14 | # Simulation parameters # 15 | ########################################################## 16 | debug-on-errors = true 17 | print-undisposed = true 18 | 19 | **.scalar-recording = true 20 | **.vector-recording = true 21 | 22 | *.playgroundSizeX = 3500m 23 | *.playgroundSizeY = 3500m 24 | *.playgroundSizeZ = 50m 25 | 26 | 27 | ########################################################## 28 | # Annotation parameters # 29 | ########################################################## 30 | *.annotations.draw = true 31 | 32 | ########################################################## 33 | # Obstacle parameters # 34 | ########################################################## 35 | *.obstacles.obstacles = xmldoc("config.xml", "//AnalogueModel[@type='SimpleObstacleShadowing']/obstacles") 36 | 37 | ########################################################## 38 | # TraCIScenarioManager parameters # 39 | ########################################################## 40 | *.manager.updateInterval = 0.5s 41 | *.manager.host = "localhost" 42 | *.manager.port = 9999 43 | *.manager.autoShutdown = true 44 | *.manager.launchConfig = xmldoc("task_offloading.launchd.xml") 45 | 46 | ########################################################## 47 | # RSU SETTINGS # 48 | # # 49 | # # 50 | ########################################################## 51 | # *.rsu[0].mobility.x = 2000 52 | # *.rsu[0].mobility.y = 2000 53 | # *.rsu[0].mobility.z = 3 54 | # 55 | # *.rsu[*].applType = "RSU" 56 | # *.rsu[*].appl.headerLength = 80 bit 57 | # *.rsu[*].appl.sendBeacons = false 58 | # *.rsu[*].appl.dataOnSch = false 59 | # *.rsu[*].appl.beaconInterval = 1s 60 | # *.rsu[*].appl.beaconUserPriority = 7 61 | # *.rsu[*].appl.dataUserPriority = 5 62 | # *.rsu[*].nic.phy80211p.antennaOffsetZ = 0 m 63 | 64 | ########################################################## 65 | # 11p specific parameters # 66 | # # 67 | # NIC-Settings # 68 | ########################################################## 69 | *.connectionManager.sendDirect = true 70 | *.connectionManager.maxInterfDist = 2600m 71 | *.connectionManager.drawMaxIntfDist = false 72 | 73 | *.**.nic.mac1609_4.useServiceChannel = false 74 | 75 | *.**.nic.mac1609_4.txPower = 20mW 76 | *.**.nic.mac1609_4.bitrate = 6Mbps 77 | *.**.nic.phy80211p.minPowerLevel = -110dBm 78 | 79 | *.**.nic.phy80211p.useNoiseFloor = true 80 | *.**.nic.phy80211p.noiseFloor = -98dBm 81 | 82 | *.**.nic.phy80211p.decider = xmldoc("config.xml") 83 | *.**.nic.phy80211p.analogueModels = xmldoc("config.xml") 84 | *.**.nic.phy80211p.usePropagationDelay = true 85 | 86 | *.**.nic.phy80211p.antenna = xmldoc("antenna.xml", "/root/Antenna[@id='monopole']") 87 | *.**[*].nic.phy80211p.antennaOffsetY = 0 m 88 | *.**[*].nic.phy80211p.antennaOffsetZ = 1.895 m 89 | 90 | # Specify if the app have to use auto ACKs between the messages 91 | # MAC layer 92 | *.**.nic.mac1609_4.useAcks = ${useAcks = false} 93 | # Application layer 94 | *.veinsApp.useAcks = ${$useAcks} 95 | 96 | ########################################################## 97 | # App Layer # 98 | ########################################################## 99 | # Match the car and bus modules with the XML .rou file 100 | *.manager.moduleDisplayString = "BUS='i=veins/node/car_vs' CAR='i=veins/node/car_vs'" 101 | *.manager.moduleType = "BUS=org.car2x.veins.nodes.Car CAR=org.car2x.veins.nodes.Car" 102 | *.manager.moduleName = "BUS=bus CAR=car" 103 | 104 | # Select the application types for the car and the bus 105 | *.bus[*].applType = "TaskGenerator" 106 | *.car[*].applType = "Worker" 107 | 108 | # Common settings shared between cars and buses 109 | *.**[*].appl.headerLength = 80 bit 110 | *.**[*].appl.sendBeacons = false 111 | *.**[*].appl.dataOnSch = false 112 | *.**[*].appl.beaconInterval = 1s 113 | 114 | ########################################################## 115 | # Mobility # 116 | ########################################################## 117 | *.**[*].veinsmobility.x = 0 118 | *.**[*].veinsmobility.y = 0 119 | *.**[*].veinsmobility.z = 0 120 | *.**[*].veinsmobility.setHostSpeed = false 121 | 122 | ########################################################## 123 | # Task offloading parameters # 124 | # -- Task generator -- # 125 | ########################################################## 126 | # Time to wait in s for the help request to be sent 127 | *.bus[*].appl.randomTimeFirstHelpMessage = uniform(30s, 40s) 128 | 129 | *.bus[*].appl.randomTimeHelpRequest = uniform(1s, 2s) 130 | 131 | # Time in ms for the bus to wait for ok messages 132 | *.bus[*].appl.busWaitingTimeForAvailability = uniform(100ms, 200ms) 133 | 134 | # Time in s for data computation extra time 135 | *.bus[*].appl.dataComputationThreshold = uniform(500ms, 600ms) 136 | 137 | # Total computation load for the bus 138 | *.bus[*].appl.computationLoad = 10MB 139 | 140 | # Bus load capacity 141 | *.bus[*].appl.busVehicleLoad = 4MB 142 | 143 | # The minimum vehicle load accepted by the bus 144 | *.bus[*].appl.minimumVehicleLoadRequested = 700kB 145 | 146 | # Select sorting algorithm for load balancing 147 | # Types available: FIFO, ComputationTime 148 | *.loadBalancingAlgorithm.typename = "ComputationTime" 149 | 150 | ########################################################## 151 | # Task offloading parameters # 152 | # -- Worker -- # 153 | ########################################################## 154 | # These parameters sets the probability of a vehicle to remain available 155 | # after them computation (Piggybacking) 156 | *.car[*].appl.stillAvailableProbability = uniform(0, 1) 157 | *.car[*].appl.stillAvailableThreshold = 0.5 158 | 159 | # The common load of all vehicles except for bus 160 | *.car[*].appl.commonVehicleLoad = 1MB 161 | 162 | # Time in ms for the ok messages 163 | *.car[*].appl.vehicleAvailabilityMessageTime = uniform(0ms, 100ms) 164 | 165 | # Time in s for ack message extra time 166 | *.car[*].appl.ackMessageThreshold = uniform(300ms, 400ms) 167 | 168 | # These parameters are for the current load of a vehicle and the 169 | # respective CPU frequency 170 | *.car[*].appl.randomVehicleFreeLoadPercentage = uniform(0, 1) 171 | *.car[*].appl.randomVehicleCpuFreq = uniform(1.20GHz, 2.70GHz) 172 | 173 | ########################################################## 174 | # Task offloading parameters # 175 | # -- Shared -- # 176 | ########################################################## 177 | 178 | [Config Default] 179 | 180 | [Config WithBeaconing] 181 | # *.rsu[*].appl.sendBeacons = true 182 | *.**[*].appl.sendBeacons = true 183 | 184 | [Config WithChannelSwitching] 185 | *.**.nic.mac1609_4.useServiceChannel = true 186 | *.**[*].appl.dataOnSch = true 187 | # *.rsu[*].appl.dataOnSch = true 188 | 189 | -------------------------------------------------------------------------------- /simulations/task_offloading/task_offloading.launchd.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /simulations/task_offloading/task_offloading.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 task_offloading.simulations.task_offloading; 17 | 18 | import task_offloading.app.loadBalancing.sortingAlgorithm.ISorting; 19 | import org.car2x.veins.base.connectionManager.ConnectionManager; 20 | import org.car2x.veins.base.modules.BaseWorldUtility; 21 | import org.car2x.veins.modules.mobility.traci.TraCIScenarioManager*; 22 | import org.car2x.veins.modules.obstacle.ObstacleControl; 23 | import org.car2x.veins.modules.world.annotations.AnnotationManager; 24 | import org.car2x.veins.nodes.Car; 25 | import org.car2x.veins.visualizer.roads.RoadsCanvasVisualizer; 26 | 27 | network task_offloading 28 | { 29 | parameters: 30 | double playgroundSizeX @unit(m); // x size of the area the nodes are in (in meters) 31 | double playgroundSizeY @unit(m); // y size of the area the nodes are in (in meters) 32 | double playgroundSizeZ @unit(m); // z size of the area the nodes are in (in meters) 33 | @display("bgb=3500,3500"); 34 | submodules: 35 | loadBalancingAlgorithm: like ISorting { 36 | @display("i=block/cogwheel;p=248,140"); 37 | } 38 | 39 | obstacles: ObstacleControl { 40 | @display("p=616.704,378.43198"); 41 | } 42 | annotations: AnnotationManager { 43 | @display("p=644.73596,378.43198"); 44 | } 45 | connectionManager: ConnectionManager { 46 | parameters: 47 | @display("p=150,0;i=abstract/multicast"); 48 | } 49 | world: BaseWorldUtility { 50 | parameters: 51 | playgroundSizeX = veins_eval_by_version(veins_omnetpp_buildnum(), "playgroundSizeX", 1525, "parent.playgroundSizeX"); 52 | playgroundSizeY = veins_eval_by_version(veins_omnetpp_buildnum(), "playgroundSizeY", 1525, "parent.playgroundSizeY"); 53 | playgroundSizeZ = veins_eval_by_version(veins_omnetpp_buildnum(), "playgroundSizeZ", 1525, "parent.playgroundSizeZ"); 54 | @display("p=413.472,329.37598;i=misc/globe"); 55 | } 56 | manager: TraCIScenarioManagerLaunchd { 57 | parameters: 58 | @display("p=897.0239,455.52"); 59 | } 60 | roadsCanvasVisualizer: RoadsCanvasVisualizer { 61 | @display("p=679.77594,329.37598"); 62 | } 63 | bus[0]: Car { 64 | @display("p=532.608,490.55997"); 65 | } 66 | car[0]: Car { 67 | @display("p=469.53598,406.464"); 68 | } 69 | 70 | connections allowunconnected: 71 | } 72 | -------------------------------------------------------------------------------- /simulations/task_offloading/task_offloading.rou.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /simulations/task_offloading/task_offloading.sumo.cfg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /simulations/veins/README: -------------------------------------------------------------------------------- 1 | Veins tutorial example. 2 | 3 | This simulation requires veins_launchd to be started and listening for 4 | connections on a TCP socket, e.g. using "~/src/veins/bin/veins_launchd -vv". 5 | 6 | -------------------------------------------------------------------------------- /simulations/veins/RSUExampleScenario.ned: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2017 Christoph Sommer 3 | // 4 | // Documentation for these modules is at http://veins.car2x.org/ 5 | // 6 | // SPDX-License-Identifier: GPL-2.0-or-later 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | // 22 | 23 | package task_offloading.simulations.veins; 24 | 25 | import org.car2x.veins.nodes.RSU; 26 | import org.car2x.veins.nodes.Scenario; 27 | 28 | network RSUExampleScenario extends Scenario 29 | { 30 | submodules: 31 | rsu[1]: RSU { 32 | @display("p=150,140;i=veins/sign/yellowdiamond;is=vs"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /simulations/veins/antenna.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /simulations/veins/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /simulations/veins/erlangen.launchd.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /simulations/veins/erlangen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connets/task_offloading/ee1f9916aebdcc5fd3ff039fdc5abf8ff6acebc8/simulations/veins/erlangen.png -------------------------------------------------------------------------------- /simulations/veins/erlangen.rou.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /simulations/veins/erlangen.sumo.cfg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /simulations/veins/omnetpp.ini: -------------------------------------------------------------------------------- 1 | [General] 2 | cmdenv-express-mode = true 3 | cmdenv-autoflush = true 4 | cmdenv-status-frequency = 1s 5 | **.cmdenv-log-level = info 6 | 7 | image-path = ../../images 8 | 9 | network = RSUExampleScenario 10 | 11 | ########################################################## 12 | # Simulation parameters # 13 | ########################################################## 14 | debug-on-errors = true 15 | print-undisposed = true 16 | 17 | sim-time-limit = 200s 18 | 19 | **.scalar-recording = true 20 | **.vector-recording = true 21 | 22 | *.playgroundSizeX = 2500m 23 | *.playgroundSizeY = 2500m 24 | *.playgroundSizeZ = 50m 25 | 26 | 27 | ########################################################## 28 | # Annotation parameters # 29 | ########################################################## 30 | *.annotations.draw = true 31 | 32 | ########################################################## 33 | # Obstacle parameters # 34 | ########################################################## 35 | *.obstacles.obstacles = xmldoc("config.xml", "//AnalogueModel[@type='SimpleObstacleShadowing']/obstacles") 36 | 37 | ########################################################## 38 | # TraCIScenarioManager parameters # 39 | ########################################################## 40 | *.manager.updateInterval = 1s 41 | *.manager.host = "localhost" 42 | *.manager.port = 9999 43 | *.manager.autoShutdown = true 44 | *.manager.launchConfig = xmldoc("erlangen.launchd.xml") 45 | 46 | ########################################################## 47 | # RSU SETTINGS # 48 | # # 49 | # # 50 | ########################################################## 51 | *.rsu[0].mobility.x = 2000 52 | *.rsu[0].mobility.y = 2000 53 | *.rsu[0].mobility.z = 3 54 | 55 | *.rsu[*].applType = "TraCIDemoRSU11p" 56 | *.rsu[*].appl.headerLength = 80 bit 57 | *.rsu[*].appl.sendBeacons = false 58 | *.rsu[*].appl.dataOnSch = false 59 | *.rsu[*].appl.beaconInterval = 1s 60 | *.rsu[*].appl.beaconUserPriority = 7 61 | *.rsu[*].appl.dataUserPriority = 5 62 | *.rsu[*].nic.phy80211p.antennaOffsetZ = 0 m 63 | 64 | ########################################################## 65 | # 11p specific parameters # 66 | # # 67 | # NIC-Settings # 68 | ########################################################## 69 | *.connectionManager.sendDirect = true 70 | *.connectionManager.maxInterfDist = 2600m 71 | *.connectionManager.drawMaxIntfDist = false 72 | 73 | *.**.nic.mac1609_4.useServiceChannel = false 74 | 75 | *.**.nic.mac1609_4.txPower = 20mW 76 | *.**.nic.mac1609_4.bitrate = 6Mbps 77 | *.**.nic.phy80211p.minPowerLevel = -110dBm 78 | 79 | *.**.nic.phy80211p.useNoiseFloor = true 80 | *.**.nic.phy80211p.noiseFloor = -98dBm 81 | 82 | *.**.nic.phy80211p.decider = xmldoc("config.xml") 83 | *.**.nic.phy80211p.analogueModels = xmldoc("config.xml") 84 | *.**.nic.phy80211p.usePropagationDelay = true 85 | 86 | *.**.nic.phy80211p.antenna = xmldoc("antenna.xml", "/root/Antenna[@id='monopole']") 87 | *.node[*].nic.phy80211p.antennaOffsetY = 0 m 88 | *.node[*].nic.phy80211p.antennaOffsetZ = 1.895 m 89 | 90 | ########################################################## 91 | # App Layer # 92 | ########################################################## 93 | *.node[*].applType = "TraCIDemo11p" 94 | *.node[*].appl.headerLength = 80 bit 95 | *.node[*].appl.sendBeacons = false 96 | *.node[*].appl.dataOnSch = false 97 | *.node[*].appl.beaconInterval = 1s 98 | 99 | ########################################################## 100 | # Mobility # 101 | ########################################################## 102 | *.node[*].veinsmobility.x = 0 103 | *.node[*].veinsmobility.y = 0 104 | *.node[*].veinsmobility.z = 0 105 | *.node[*].veinsmobility.setHostSpeed = false 106 | *.node[*0].veinsmobility.accidentCount = 1 107 | *.node[*0].veinsmobility.accidentStart = 73s 108 | *.node[*0].veinsmobility.accidentDuration = 50s 109 | 110 | [Config Default] 111 | 112 | [Config WithBeaconing] 113 | *.rsu[*].appl.sendBeacons = true 114 | *.node[*].appl.sendBeacons = true 115 | 116 | [Config WithChannelSwitching] 117 | *.**.nic.mac1609_4.useServiceChannel = true 118 | *.node[*].appl.dataOnSch = true 119 | *.rsu[*].appl.dataOnSch = true 120 | 121 | -------------------------------------------------------------------------------- /simulations/veins/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright (C) 2011 Christoph Sommer 5 | # 6 | # Documentation for these modules is at http://veins.car2x.org/ 7 | # 8 | # SPDX-License-Identifier: GPL-2.0-or-later 9 | # 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2 of the License, or 13 | # (at your option) any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program; if not, write to the Free Software 22 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 | # 24 | 25 | exec ../../bin/veins_run "$@" 26 | -------------------------------------------------------------------------------- /src/app/Task.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 "Task.h" 17 | 18 | using namespace task_offloading; 19 | 20 | /** 21 | * Constructors section 22 | */ 23 | 24 | Task::Task() { 25 | this->id = 0; 26 | this->data = 10e6; 27 | this->helpReceivedCounter = 0; 28 | this->dataPartitionId = 0; 29 | this->loadBalancingId = 0; 30 | this->availableReceivedCounter = 0; 31 | this->responseReceivedCounter = 0; 32 | this->cpi = 1; 33 | } 34 | 35 | Task::Task(int id, double data, double loadRequested, int cpi) { 36 | this->id = id; 37 | this->data = data; 38 | this->minimumLoadRequested = loadRequested; 39 | this->helpReceivedCounter = 0; 40 | this->dataPartitionId = 0; 41 | this->loadBalancingId = 0; 42 | this->availableReceivedCounter = 0; 43 | this->responseReceivedCounter = 0; 44 | this->cpi = cpi; 45 | } 46 | 47 | Task::~Task() { 48 | } 49 | 50 | /** 51 | * Getters section 52 | */ 53 | 54 | /** 55 | * Get the current id of the task 56 | * 57 | * @return int 58 | */ 59 | int Task::getId() { 60 | return this->id; 61 | } 62 | 63 | /** 64 | * Get the total computation data 65 | * 66 | * @return double 67 | */ 68 | double Task::getData() { 69 | return this->data; 70 | } 71 | 72 | /** 73 | * Get the counter of how many times the BUS received help 74 | * 75 | * @return int 76 | */ 77 | int Task::getHelpReceivedCounter() { 78 | return this->helpReceivedCounter; 79 | } 80 | 81 | 82 | /** 83 | * Get the current data partition id 84 | * 85 | * @return int 86 | */ 87 | int Task::getDataPartitionId() { 88 | return this->dataPartitionId; 89 | } 90 | 91 | /** 92 | * Get the current load balancing id 93 | * 94 | * @return int 95 | */ 96 | int Task::getLoadBalancingId() { 97 | return this->loadBalancingId; 98 | } 99 | 100 | /** 101 | * Get the counter of vehicles available 102 | * 103 | * @return int 104 | */ 105 | int Task::getAvailableReceivedCounter() { 106 | return this->availableReceivedCounter; 107 | } 108 | 109 | /** 110 | * Get the counter of response received from vehicles 111 | * 112 | * @return int 113 | */ 114 | int Task::getResponseReceivedCounter() { 115 | return this->responseReceivedCounter; 116 | } 117 | 118 | /** 119 | * Get the minimum load requested accepted by bus 120 | * 121 | * @return double 122 | */ 123 | double Task::getMinimumLoadRequested() { 124 | return this->minimumLoadRequested; 125 | } 126 | 127 | /** 128 | * Get the CPI for the task, it's a constant that represent the difficulty of it 129 | * 130 | * @return int 131 | */ 132 | int Task::getCpi() { 133 | return this->cpi; 134 | } 135 | 136 | /** 137 | * Setters section 138 | */ 139 | 140 | /** 141 | * Set the current task id 142 | * 143 | * @return void 144 | */ 145 | void Task::setId(int newId) { 146 | this->id = newId; 147 | } 148 | 149 | /** 150 | * Set the current computation load 151 | * 152 | * @return void 153 | */ 154 | void Task::setData(double newData) { 155 | this->data = newData; 156 | } 157 | 158 | /** 159 | * Increment the help received counter by one 160 | * 161 | * @return void 162 | */ 163 | void Task::setHelpReceivedCounter(int newCounter) { 164 | this->helpReceivedCounter = newCounter; 165 | } 166 | 167 | /** 168 | * Set the new data partition id 169 | * 170 | * @return void 171 | */ 172 | void Task::setDataPartitionId(int newDataPartitionId) { 173 | this->dataPartitionId = newDataPartitionId; 174 | } 175 | 176 | /** 177 | * Set the new load balancing id 178 | * 179 | * @return void 180 | */ 181 | void Task::setLoadBalancingId(int newLoadBalancingId) { 182 | this->loadBalancingId = newLoadBalancingId; 183 | } 184 | 185 | /** 186 | * Set the new vehicles available counter 187 | * 188 | * @return void 189 | */ 190 | void Task::setAvailableReceivedCounter(int newCounter) { 191 | this->availableReceivedCounter = newCounter; 192 | } 193 | 194 | /** 195 | * Set the new responses received counter 196 | * 197 | * @return void 198 | */ 199 | void Task::setResponseReceivedCounter(int newCounter) { 200 | this->responseReceivedCounter = newCounter; 201 | } 202 | 203 | /** 204 | * Set the minimum load requested accepted by bus 205 | * 206 | * @return void 207 | */ 208 | void Task::setMinimumLoadRequested(double newMinimumLoad) { 209 | this->minimumLoadRequested = newMinimumLoad; 210 | } 211 | 212 | /** 213 | * Set the CPI for the task, it's a constant that represent the difficulty of it 214 | * 215 | * @return void 216 | */ 217 | void Task::setCpi(int newCpi) { 218 | this->cpi = newCpi; 219 | } 220 | -------------------------------------------------------------------------------- /src/app/Task.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 APP_TASK_H_ 17 | #define APP_TASK_H_ 18 | 19 | #include "veins/veins.h" 20 | #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h" 21 | 22 | namespace task_offloading { 23 | class Task { 24 | public: 25 | Task(); 26 | Task(int id, double data, double loadRequested, int cpi); 27 | int getId(); 28 | double getData(); 29 | int getHelpReceivedCounter(); 30 | int getDataPartitionId(); 31 | int getLoadBalancingId(); 32 | int getAvailableReceivedCounter(); 33 | int getResponseReceivedCounter(); 34 | double getMinimumLoadRequested(); 35 | int getCpi(); 36 | void setId(int newId); 37 | void setData(double newData); 38 | void setHelpReceivedCounter(int newCounter); 39 | void setDataPartitionId(int newDataPartitionId); 40 | void setLoadBalancingId(int newLoadBalancingId); 41 | void setAvailableReceivedCounter(int newCounter); 42 | void setResponseReceivedCounter(int newCounter); 43 | void setMinimumLoadRequested(double newMinimumLoad); 44 | void setCpi(int newCpi); 45 | virtual ~Task(); 46 | 47 | private: 48 | int id; 49 | double data; 50 | double minimumLoadRequested; 51 | int cpi; 52 | int helpReceivedCounter; 53 | int dataPartitionId; 54 | int loadBalancingId; 55 | int availableReceivedCounter; 56 | int responseReceivedCounter; 57 | }; 58 | } 59 | #endif /* APP_TASK_H_ */ 60 | -------------------------------------------------------------------------------- /src/app/TaskGenerator.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2016 David Eckhoff 3 | // 4 | // Documentation for these modules is at http://veins.car2x.org/ 5 | // 6 | // SPDX-License-Identifier: GPL-2.0-or-later 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | // 22 | 23 | #include "TaskGenerator.h" 24 | 25 | #include "app/messages/HelpMessage_m.h" 26 | #include "app/messages/AvailabilityMessage_m.h" 27 | #include "app/messages/AckMessage_m.h" 28 | #include "app/messages/DataMessage_m.h" 29 | #include "app/messages/ResponseMessage_m.h" 30 | #include "app/messages/AckTimerMessage_m.h" 31 | #include "app/messages/LoadBalanceTimerMessage_m.h" 32 | #include "app/messages/ComputationTimerMessage_m.h" 33 | #include "app/messages/UpdateAvailabilityMessage_m.h" 34 | 35 | using namespace task_offloading; 36 | 37 | Define_Module(task_offloading::TaskGenerator); 38 | 39 | void TaskGenerator::initialize(int stage) 40 | { 41 | veins::DemoBaseApplLayer::initialize(stage); 42 | 43 | if (stage == 0) { 44 | // Initializing members and pointers of your application goes here 45 | lastDroveAt = simTime(); 46 | 47 | // BUS SECTION 48 | // Set the BUS index 49 | busIndex = findHost()->getIndex(); 50 | 51 | // Initialize the BUS state 52 | busState = BusContext(new Help); 53 | 54 | // Initialize the load balancing algorithm 55 | loadBalancingAlgorithm = check_and_cast(findModuleByPath("task_offloading.loadBalancingAlgorithm")); 56 | 57 | // Registering all signals 58 | startTask = registerSignal("task_started"); 59 | stopTask = registerSignal("task_stopped"); 60 | startBalance = registerSignal("start_balance_loading"); 61 | stopBalance = registerSignal("stop_balance_loading"); 62 | startHelp = registerSignal("start_bus_help_rq"); 63 | startDataMessages = registerSignal("start_sending_data"); 64 | stopResponseMessages = registerSignal("stop_getting_response"); 65 | } 66 | } 67 | 68 | void TaskGenerator::finish() 69 | { 70 | veins::DemoBaseApplLayer::finish(); 71 | } 72 | 73 | void TaskGenerator::onBSM(veins::DemoSafetyMessage* bsm) 74 | { 75 | // Your application has received a beacon message from another car or RSU 76 | } 77 | 78 | void TaskGenerator::onWSM(veins::BaseFrame1609_4* wsm) 79 | { 80 | /************************************************************************ 81 | Your application has received a data message from another car or RSU 82 | ************************************************************************/ 83 | 84 | // SECTION - When the bus receives the ok messages 85 | if (AvailabilityMessage* availabilityMessage = dynamic_cast(wsm)) { 86 | handleAvailabilityMessage(availabilityMessage); 87 | } 88 | 89 | // SECTION - When the bus receive the response message 90 | if (ResponseMessage* responseMessage = dynamic_cast(wsm)) { 91 | handleResponseMessage(responseMessage); 92 | } 93 | } 94 | 95 | void TaskGenerator::onWSA(veins::DemoServiceAdvertisment* wsa) 96 | { 97 | // Your application has received a service advertisement from another car or RSU 98 | } 99 | 100 | void TaskGenerator::handleSelfMsg(cMessage* msg) 101 | { 102 | // This method is for self messages (mostly timers) 103 | // Timer for help message 104 | if (LoadBalanceTimerMessage* loadBalanceMsg = dynamic_cast(msg)) { 105 | // If I'm the bus and I've received help then load balance 106 | // otherwise back to help messages 107 | if (findHost()->getIndex() == busIndex && helpers.size() > 0 && busState.getCurrentState() == 1) { 108 | // Call to load balancing function 109 | balanceLoad(); 110 | } else if (helpers.size() == 0) { 111 | // Disable load balancing 112 | busState.setState(new Help); 113 | } 114 | } 115 | 116 | // Timer for data computation 117 | if (ComputationTimerMessage* computationTimerMessage = dynamic_cast(msg)) { 118 | const DataMessage* data = computationTimerMessage->getData(); 119 | sendAgainData(data); 120 | } 121 | 122 | // Timer for data message 123 | if (DataMessage* dataMsg = dynamic_cast(msg)) { 124 | // Send signal for data message statistic with the host ID 125 | emit(startDataMessages, dataMsg->getHostIndex()); 126 | 127 | sendDown(dataMsg->dup()); 128 | } 129 | 130 | // Timer for ACK message 131 | if (AckMessage* ackMsg = dynamic_cast(msg)) { 132 | sendDown(ackMsg->dup()); 133 | } 134 | } 135 | 136 | void TaskGenerator::handlePositionUpdate(cObject* obj) 137 | { 138 | // The vehicle has moved. Code that reacts to new positions goes here. 139 | // Member variables such as currentPosition and currentSpeed are updated in the parent class 140 | 141 | veins::DemoBaseApplLayer::handlePositionUpdate(obj); 142 | 143 | vehicleHandler(); 144 | 145 | lastDroveAt = simTime(); 146 | } 147 | -------------------------------------------------------------------------------- /src/app/TaskGenerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2016 David Eckhoff 3 | // 4 | // Documentation for these modules is at http://veins.car2x.org/ 5 | // 6 | // SPDX-License-Identifier: GPL-2.0-or-later 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | // 22 | 23 | #pragma once 24 | 25 | #include "veins/veins.h" 26 | 27 | #include "app/Task.h" 28 | #include "app/messages/HelpMessage_m.h" 29 | #include "app/messages/AvailabilityMessage_m.h" 30 | #include "app/messages/DataMessage_m.h" 31 | #include "app/messages/ResponseMessage_m.h" 32 | #include "app/vehiclesHandling/HelperVehicleInfo.h" 33 | #include "app/loadBalancing/sortingAlgorithm/BaseSorting.h" 34 | #include "loadBalancing/BusState.h" 35 | #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h" 36 | 37 | using namespace omnetpp; 38 | 39 | namespace task_offloading { 40 | 41 | /** 42 | * @brief 43 | * This is a stub for a typical Veins application layer. 44 | * Most common functions are overloaded. 45 | * See MyVeinsApp.cc for hints 46 | * 47 | * @author David Eckhoff 48 | * 49 | */ 50 | 51 | class VEINS_API TaskGenerator : public veins::DemoBaseApplLayer { 52 | public: 53 | void initialize(int stage) override; 54 | void finish() override; 55 | 56 | private: 57 | // Simulations signals 58 | // SECTION - Task 59 | simsignal_t startTask; 60 | simsignal_t stopTask; 61 | 62 | // SECTION - BalanceLoad 63 | simsignal_t startBalance; 64 | simsignal_t stopBalance; 65 | 66 | // SECTION - Help requests collection 67 | simsignal_t startHelp; 68 | 69 | // SECTION - Data messages statistics 70 | simsignal_t startDataMessages; 71 | 72 | // SECTION - Response messages statistics 73 | simsignal_t stopResponseMessages; 74 | 75 | protected: 76 | simtime_t lastDroveAt; 77 | std::map helpers; 78 | std::map tasks; 79 | std::list helpersOrderedList; 80 | int busIndex; 81 | BusContext busState; 82 | BaseSorting* loadBalancingAlgorithm; 83 | 84 | protected: 85 | void onBSM(veins::DemoSafetyMessage* bsm) override; 86 | void onWSM(veins::BaseFrame1609_4* wsm) override; 87 | void onWSA(veins::DemoServiceAdvertisment* wsa) override; 88 | 89 | void handleSelfMsg(cMessage* msg) override; 90 | void handleAvailabilityMessage(AvailabilityMessage* okMsg); 91 | void handleResponseMessage(ResponseMessage* responseMsg); 92 | void sendAgainData(const DataMessage* data); 93 | void balanceLoad(); 94 | void vehicleHandler(); 95 | void handlePositionUpdate(cObject* obj) override; 96 | }; 97 | } 98 | -------------------------------------------------------------------------------- /src/app/TaskGenerator.ned: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2016 David Eckhoff 3 | // 4 | // Documentation for these modules is at http://veins.car2x.org/ 5 | // 6 | // SPDX-License-Identifier: GPL-2.0-or-later 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | // 22 | 23 | package task_offloading.app; 24 | import org.car2x.veins.modules.application.ieee80211p.DemoBaseApplLayer; 25 | 26 | simple TaskGenerator extends DemoBaseApplLayer 27 | { 28 | parameters: 29 | // The random time for te first help message 30 | volatile double randomTimeFirstHelpMessage @unit(s) = default(uniform(30s, 40s)); 31 | 32 | // The random time for the other help messages 33 | volatile double randomTimeHelpRequest @unit(s) = default(uniform(1s, 2s)); 34 | 35 | // The minimum load requested accepted by bus 36 | double minimumVehicleLoadRequested @unit(byte) = default(300kB); 37 | 38 | // The bus load 39 | double busVehicleLoad @unit(byte) = default(4MB); 40 | 41 | // The total data to compute 42 | double computationLoad @mutable @unit(byte) = default(10MB); 43 | 44 | // Set this to true if you want to use automatic ack messages 45 | bool useAcks = default(false); 46 | 47 | // Bus time to wait for availability messages 48 | double busWaitingTimeForAvailability @unit(s) = default(uniform(100ms, 200ms)); 49 | 50 | // Extra time threshold for data computation 51 | volatile double dataComputationThreshold @unit(s) = default(uniform(100ms, 200ms)); 52 | 53 | // The load balancing sorting algorithm 54 | string sortingAlgorithm = default("FIFO"); 55 | 56 | // Override default veins data length bits 57 | dataLengthBits = 0bit; 58 | 59 | // General statistic for task time 60 | @signal[task_started](type = simtime_t); 61 | @signal[task_stopped](type = simtime_t); 62 | @statistic[startTimeTask](source = task_started; record = vector,stats; interpolationmode = none); 63 | @statistic[stopTimeTask](source = task_stopped; record = vector,stats; interpolationmode = none); 64 | 65 | // Statistics for balance loading 66 | @signal[start_balance_loading](type = simtime_t); 67 | @signal[stop_balance_loading](type = simtime_t); 68 | @statistic[startBalanceLoad](source = start_balance_loading; record = vector,stats; interpolationmode = none); 69 | @statistic[stopBalanceLoad](source = stop_balance_loading; record = vector,stats; interpolationmode = none); 70 | 71 | // Statistics for collecting help requests 72 | @signal[start_bus_help_rq](type = simtime_t); 73 | @statistic[startHelpRequests](source = start_bus_help_rq; record = vector,stats; interpolationmode = none); 74 | 75 | // Statistics for sending data messages 76 | @signal[start_sending_data](type = int); 77 | @statistic[startDataMessages](source = start_sending_data; record = vector,stats; interpolationmode = none); 78 | 79 | // Statistics for sending response messages 80 | @signal[stop_getting_response](type = int); 81 | @statistic[stopResponseMessages](source = stop_getting_response; record = vector,stats; interpolationmode = none); 82 | 83 | @class(task_offloading::TaskGenerator); 84 | @display("i=block/app2"); 85 | } 86 | -------------------------------------------------------------------------------- /src/app/Worker.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2016 David Eckhoff 3 | // 4 | // Documentation for these modules is at http://veins.car2x.org/ 5 | // 6 | // SPDX-License-Identifier: GPL-2.0-or-later 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | // 22 | 23 | #include "Worker.h" 24 | 25 | #include "app/messages/HelpMessage_m.h" 26 | #include "app/messages/AvailabilityMessage_m.h" 27 | #include "app/messages/AckMessage_m.h" 28 | #include "app/messages/DataMessage_m.h" 29 | #include "app/messages/ResponseMessage_m.h" 30 | #include "app/messages/AckTimerMessage_m.h" 31 | #include "app/messages/LoadBalanceTimerMessage_m.h" 32 | #include "app/messages/ComputationTimerMessage_m.h" 33 | #include "app/messages/UpdateAvailabilityMessage_m.h" 34 | 35 | using namespace task_offloading; 36 | 37 | Define_Module(task_offloading::Worker); 38 | 39 | void Worker::initialize(int stage) 40 | { 41 | veins::DemoBaseApplLayer::initialize(stage); 42 | 43 | if (stage == 0) { 44 | // Initializing members and pointers of your application goes here 45 | lastDroveAt = simTime(); 46 | 47 | // Initialize my cpu freq 48 | cpuFreq = 0; 49 | 50 | // Initialize data partition id 51 | currentDataPartitionId = -1; 52 | 53 | // Initialize the probability to be still available after computation 54 | stillAvailableProbability = false; 55 | 56 | // Registering all signals 57 | stopHelp = registerSignal("stop_bus_help_rq"); 58 | stopDataMessages = registerSignal("stop_sending_data"); 59 | startResponseMessages = registerSignal("start_getting_response"); 60 | availableMessageSent = registerSignal("available_message_sent"); 61 | availableMessageLoad = registerSignal("available_message_load"); 62 | } 63 | } 64 | 65 | void Worker::finish() 66 | { 67 | veins::DemoBaseApplLayer::finish(); 68 | } 69 | 70 | void Worker::onBSM(veins::DemoSafetyMessage* bsm) 71 | { 72 | // Your application has received a beacon message from another car or RSU 73 | } 74 | 75 | void Worker::onWSM(veins::BaseFrame1609_4* wsm) 76 | { 77 | /************************************************************************ 78 | Your application has received a data message from a bus 79 | ************************************************************************/ 80 | 81 | // SECTION - When the host receive an help message 82 | if (HelpMessage* helpMessage = dynamic_cast(wsm)) { 83 | handleHelpMessage(helpMessage); 84 | } 85 | 86 | // SECTION - When the host receive the data message 87 | if (DataMessage* dataMessage = dynamic_cast(wsm)) { 88 | handleDataMessage(dataMessage); 89 | } 90 | 91 | // SECTION - When the host receive the ACK message 92 | if (AckMessage* ackMessage = dynamic_cast(wsm)) { 93 | // Check if I'm the host for the ack message 94 | if (ackMessage->getHostIndex() == findHost()->getIndex()) { 95 | currentDataPartitionId = -1; 96 | 97 | // Color the vehicle in white when computation ends 98 | findHost()->getDisplayString().setTagArg("i", 1, "white"); 99 | } 100 | } 101 | } 102 | 103 | void Worker::onWSA(veins::DemoServiceAdvertisment* wsa) 104 | { 105 | // Your application has received a service advertisement from a bus 106 | } 107 | 108 | void Worker::handleSelfMsg(cMessage* msg) 109 | { 110 | // Timer for ok message 111 | if (AvailabilityMessage* availabilityMessage = dynamic_cast(msg)) { 112 | // Emit the signal of ok message sent 113 | emit(availableMessageSent, simTime()); 114 | 115 | // Send the ok message 116 | sendDown(availabilityMessage->dup()); 117 | } 118 | 119 | // Timer for response message 120 | if (ResponseMessage* responseMessage = dynamic_cast(msg)) { 121 | // Send signal for response message statistic with the host ID 122 | emit(startResponseMessages, responseMessage->getHostIndex()); 123 | 124 | // Color the vehicle in white when send down the response 125 | findHost()->getDisplayString().setTagArg("i", 1, "white"); 126 | 127 | // Send the response message 128 | sendDown(responseMessage->dup()); 129 | } 130 | 131 | // Timer for re-send response message 132 | if (AckTimerMessage* ackTimerMessage = dynamic_cast(msg)) { 133 | const ResponseMessage* response = ackTimerMessage->getData(); 134 | sendAgainResponse(response); 135 | } 136 | } 137 | 138 | void Worker::handlePositionUpdate(cObject* obj) 139 | { 140 | // The vehicle has moved. Code that reacts to new positions goes here. 141 | // Member variables such as currentPosition and currentSpeed are updated in the parent class 142 | 143 | veins::DemoBaseApplLayer::handlePositionUpdate(obj); 144 | 145 | lastDroveAt = simTime(); 146 | } 147 | -------------------------------------------------------------------------------- /src/app/Worker.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2016 David Eckhoff 3 | // 4 | // Documentation for these modules is at http://veins.car2x.org/ 5 | // 6 | // SPDX-License-Identifier: GPL-2.0-or-later 7 | // 8 | // This program is free software; you can redistribute it and/or modify 9 | // it under the terms of the GNU General Public License as published by 10 | // the Free Software Foundation; either version 2 of the License, or 11 | // (at your option) any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | // GNU General Public License for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License 19 | // along with this program; if not, write to the Free Software 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | // 22 | 23 | #pragma once 24 | 25 | #include "veins/veins.h" 26 | 27 | #include "app/messages/HelpMessage_m.h" 28 | #include "app/messages/AvailabilityMessage_m.h" 29 | #include "app/messages/DataMessage_m.h" 30 | #include "app/messages/ResponseMessage_m.h" 31 | #include "app/vehiclesHandling/HelperVehicleInfo.h" 32 | #include "app/loadBalancing/sortingAlgorithm/BaseSorting.h" 33 | #include "loadBalancing/BusState.h" 34 | #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h" 35 | 36 | using namespace omnetpp; 37 | 38 | namespace task_offloading { 39 | 40 | /** 41 | * @brief 42 | * This is a stub for a typical Veins application layer. 43 | * Most common functions are overloaded. 44 | * See MyVeinsApp.cc for hints 45 | * 46 | * @author David Eckhoff 47 | * 48 | */ 49 | 50 | class VEINS_API Worker : public veins::DemoBaseApplLayer { 51 | public: 52 | void initialize(int stage) override; 53 | void finish() override; 54 | 55 | private: 56 | // Simulations signals 57 | 58 | // SECTION - Help requests collection 59 | simsignal_t stopHelp; 60 | 61 | // SECTION - Data messages statistics 62 | simsignal_t stopDataMessages; 63 | 64 | // SECTION - Response messages statistics 65 | simsignal_t startResponseMessages; 66 | 67 | // SECTION - OK messages statistics 68 | simsignal_t availableMessageSent; 69 | simsignal_t availableMessageLoad; 70 | 71 | protected: 72 | simtime_t lastDroveAt; 73 | double cpuFreq; 74 | int currentDataPartitionId; 75 | bool stillAvailableProbability; 76 | 77 | protected: 78 | void onBSM(veins::DemoSafetyMessage* bsm) override; 79 | void onWSM(veins::BaseFrame1609_4* wsm) override; 80 | void onWSA(veins::DemoServiceAdvertisment* wsa) override; 81 | 82 | void handleSelfMsg(cMessage* msg) override; 83 | void handleHelpMessage(HelpMessage* helpMsg); 84 | void handleDataMessage(DataMessage* dataMsg); 85 | void sendAgainResponse(const ResponseMessage* data); 86 | void handlePositionUpdate(cObject* obj) override; 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /src/app/Worker.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 task_offloading.app; 17 | import org.car2x.veins.modules.application.ieee80211p.DemoBaseApplLayer; 18 | 19 | simple Worker extends DemoBaseApplLayer 20 | { 21 | parameters: 22 | // The random CPU frequency 23 | volatile double randomVehicleCpuFreq @unit(Hz) = default(uniform(1.20GHz, 2.70GHz)); 24 | 25 | // The random percentage of free vehicle load 26 | volatile double randomVehicleFreeLoadPercentage = default(uniform(0, 1)); 27 | 28 | // The common vehicle load 29 | double commonVehicleLoad @unit(byte) = default(1MB); 30 | 31 | // Set this to true if you want to use automatic ack messages 32 | bool useAcks = default(false); 33 | 34 | // The probability to be still available after computation 35 | volatile double stillAvailableProbability = default(uniform(0, 1)); 36 | 37 | // The threshold for the above probability 38 | double stillAvailableThreshold = default(0.5); 39 | 40 | // The random time for the availability message 41 | double vehicleAvailabilityMessageTime @unit(s) = default(uniform(0ms, 100ms)); 42 | 43 | // The threshold for the ack messages 44 | volatile double ackMessageThreshold @unit(s) = default(uniform(50ms, 100ms)); 45 | 46 | // Override default veins data length bits 47 | dataLengthBits = 0bit; 48 | 49 | // Statistics for collecting help requests 50 | @signal[stop_bus_help_rq](type = simtime_t); 51 | @statistic[stopHelpRequests](source = stop_bus_help_rq; record = vector,stats; interpolationmode = none); 52 | 53 | // Statistics for sending data messages 54 | @signal[stop_sending_data](type = int); 55 | @statistic[stopDataMessages](source = stop_sending_data; record = vector,stats; interpolationmode = none); 56 | 57 | // Statistics for sending response messages 58 | @signal[start_getting_response](type = int); 59 | @statistic[startResponseMessages](source = start_getting_response; record = vector,stats; interpolationmode = none); 60 | 61 | // Statistics for sending and load of OK messages 62 | @signal[available_message_sent](type = simtime_t); 63 | @signal[available_message_load](type = double); 64 | @statistic[availableMessageSent](source = available_message_sent; record = vector,stats; interpolationmode = none); 65 | @statistic[availableMessageLoad](source = available_message_load; record = vector,stats; interpolationmode = none); 66 | 67 | @class(task_offloading::Worker); 68 | @display("i=block/app2"); 69 | } 70 | -------------------------------------------------------------------------------- /src/app/loadBalancing/BusState.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 "BusState.h" 17 | 18 | using namespace task_offloading; 19 | 20 | BusState::~BusState() 21 | { 22 | // 23 | } 24 | 25 | BusContext::~BusContext() { 26 | // 27 | } 28 | 29 | BusContext::BusContext() 30 | { 31 | currentState = new Help; 32 | } 33 | 34 | BusContext::BusContext(BusState* newState) 35 | { 36 | currentState = newState; 37 | } 38 | 39 | void BusContext::setState(BusState* newState) 40 | { 41 | if (currentState) { 42 | delete currentState; 43 | currentState = newState; 44 | } 45 | } 46 | 47 | int BusContext::getCurrentState() 48 | { 49 | return currentState->getCurrentState(); 50 | } 51 | 52 | int Help::getCurrentState() 53 | { 54 | return 0; 55 | } 56 | 57 | int LoadBalancing::getCurrentState() 58 | { 59 | return 1; 60 | } 61 | 62 | int DataTransfer::getCurrentState() 63 | { 64 | return 2; 65 | } 66 | 67 | int FinishedComputation::getCurrentState() 68 | { 69 | return 3; 70 | } 71 | -------------------------------------------------------------------------------- /src/app/loadBalancing/BusState.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 APP_LOADBALANCING_BUSSTATE_H_ 17 | #define APP_LOADBALANCING_BUSSTATE_H_ 18 | 19 | namespace task_offloading { 20 | class BusState 21 | { 22 | public: 23 | virtual int getCurrentState() = 0; 24 | virtual ~BusState(); 25 | }; 26 | 27 | class Help : public BusState 28 | { 29 | public: 30 | int getCurrentState(); 31 | }; 32 | 33 | class LoadBalancing : public BusState 34 | { 35 | public: 36 | int getCurrentState(); 37 | }; 38 | 39 | class DataTransfer : public BusState 40 | { 41 | public: 42 | int getCurrentState(); 43 | }; 44 | 45 | class FinishedComputation : public BusState 46 | { 47 | public: 48 | int getCurrentState(); 49 | }; 50 | 51 | class BusContext { 52 | public: 53 | BusContext(); 54 | BusContext(BusState* newState); 55 | virtual ~BusContext(); 56 | void setState(BusState* newState); 57 | int getCurrentState(); 58 | 59 | protected: 60 | BusState* currentState; 61 | }; 62 | } 63 | 64 | #endif /* APP_LOADBALANCING_BUSSTATE_H_ */ 65 | -------------------------------------------------------------------------------- /src/app/loadBalancing/LoadBalancing.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 "app/TaskGenerator.h" 17 | #include "app/messages/ComputationTimerMessage_m.h" 18 | 19 | using namespace task_offloading; 20 | 21 | void TaskGenerator::balanceLoad() 22 | { 23 | // We have to do some work -> load balance! 24 | 25 | // But first change the bus state to load balancing 26 | busState.setState(new LoadBalancing); 27 | 28 | // Then order the map of helpers by sorting them with the chosen sorting algorithm 29 | helpersOrderedList = loadBalancingAlgorithm->sort(helpers); 30 | 31 | // Store the data into a local variable so can be used 32 | double localData = tasks[0].getData(); 33 | 34 | // Emit the start of load balancing 35 | emit(startBalance, simTime()); 36 | 37 | // For each vehicle prepare the data message and send 38 | for (auto const &i: helpersOrderedList) { 39 | // Check if there's data to load 40 | if (localData > 0) { 41 | // Prepare the data message 42 | DataMessage* dataMessage = new DataMessage(); 43 | 44 | // Populate the data message 45 | 46 | // If auto acks is active then populate wsm with the sender address 47 | // otherwise populate it without address 48 | if (par("useAcks").boolValue()) { 49 | populateWSM(dataMessage, helpers[i].getAddress()); 50 | } else { 51 | populateWSM(dataMessage); 52 | } 53 | 54 | // Check if data is > 0 then update the local data variable 55 | if ((localData - helpers[i].getCurrentLoad()) > 0) { 56 | // Set the byte length 57 | dataMessage->addByteLength(helpers[i].getCurrentLoad()); 58 | 59 | // Set the message load to process 60 | dataMessage->setLoadToProcess(helpers[i].getCurrentLoad()); 61 | localData = localData - helpers[i].getCurrentLoad(); 62 | } else { 63 | // Set the byte length 64 | dataMessage->addByteLength(localData); 65 | 66 | // Set the message load to process 67 | dataMessage->setLoadToProcess(localData); 68 | localData = 0; 69 | } 70 | 71 | // Populate the other fields 72 | dataMessage->setSenderAddress(myId); 73 | dataMessage->setHostIndex(i); 74 | dataMessage->setTaskId(tasks[0].getId()); 75 | dataMessage->setPartitionId(tasks[0].getDataPartitionId()); 76 | dataMessage->setLoadBalancingId(tasks[0].getLoadBalancingId()); 77 | dataMessage->setCpi(tasks[0].getCpi()); 78 | 79 | // Calculate time for timer 80 | double CPI = tasks[0].getCpi(); 81 | double timeToCompute = helpers[i].getTotalComputationTime(CPI); 82 | 83 | dataMessage->setComputationTime(timeToCompute); 84 | 85 | // Get the current data partition id 86 | int currentPartitionId = tasks[0].getDataPartitionId(); 87 | 88 | // Save into the helper the data partition ID 89 | helpers[i].setDataPartitionId(currentPartitionId); 90 | 91 | // Schedule the data message 92 | scheduleAt(simTime(), dataMessage); 93 | 94 | // Create timer computation message for each host if auto ACKs are disabled 95 | if (par("useAcks").boolValue() == false) { 96 | ComputationTimerMessage* computationTimerMessage = new ComputationTimerMessage(); 97 | populateWSM(computationTimerMessage); 98 | computationTimerMessage->setData(dataMessage); 99 | 100 | // Calculate time to file transmission 101 | double transferTime = 10.0; 102 | 103 | scheduleAt(simTime() + timeToCompute + transferTime + par("dataComputationThreshold").doubleValue(), computationTimerMessage); 104 | } 105 | 106 | // Increment data partition ID 107 | currentPartitionId++; 108 | tasks[0].setDataPartitionId(currentPartitionId); 109 | } 110 | } 111 | 112 | // Change the bus state to data transfer 113 | busState.setState(new DataTransfer); 114 | 115 | // Emit the stop of load balancing 116 | emit(stopBalance, simTime()); 117 | } 118 | -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/BaseSorting.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 "BaseSorting.h" 17 | 18 | using namespace task_offloading; 19 | 20 | BaseSorting::BaseSorting() { 21 | // 22 | 23 | } 24 | 25 | BaseSorting::~BaseSorting() { 26 | // 27 | } 28 | -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/BaseSorting.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 APP_LOADBALANCING_SORTINGALGORITHM_BASESORTING_H_ 17 | #define APP_LOADBALANCING_SORTINGALGORITHM_BASESORTING_H_ 18 | 19 | #include "veins/veins.h" 20 | #include "app/vehiclesHandling/HelperVehicleInfo.h" 21 | #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h" 22 | 23 | namespace task_offloading { 24 | class BaseSorting : public cSimpleModule { 25 | public: 26 | BaseSorting(); 27 | virtual ~BaseSorting(); 28 | virtual std::list sort(const std::map &map) = 0; 29 | }; 30 | } 31 | 32 | #endif /* APP_LOADBALANCING_SORTINGALGORITHM_BASESORTING_H_ */ 33 | -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/ComputationTime.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 "ComputationTime.h" 17 | 18 | using namespace task_offloading; 19 | 20 | Define_Module(task_offloading::ComputationTime); 21 | 22 | ComputationTime::ComputationTime() { 23 | // 24 | 25 | } 26 | 27 | ComputationTime::~ComputationTime() { 28 | // 29 | } 30 | 31 | bool cmpComputationTime(std::pair &a, std::pair &b) { 32 | return a.second.getTotalComputationTime(a.second.getTaskCpi()) < b.second.getTotalComputationTime(b.second.getTaskCpi()); 33 | } 34 | 35 | std::list ComputationTime::sort(const std::map &map) { 36 | std::list l; 37 | 38 | std::vector> pairVector; 39 | 40 | // Copy the IDs of the map into the vector 41 | for (auto &it : map) { 42 | pairVector.push_back(it); 43 | } 44 | 45 | // Sorting the array with the cmp function defined above 46 | std::sort(pairVector.begin(), pairVector.end(), cmpComputationTime); 47 | 48 | // Fill the list with ordered IDs 49 | for (auto &it : pairVector) { 50 | l.push_back(it.first); 51 | } 52 | 53 | return l; 54 | } 55 | -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/ComputationTime.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 APP_LOADBALANCING_SORTINGALGORITHM_COMPUTATIONTIME_H_ 17 | #define APP_LOADBALANCING_SORTINGALGORITHM_COMPUTATIONTIME_H_ 18 | 19 | #include "veins/veins.h" 20 | #include "app/vehiclesHandling/HelperVehicleInfo.h" 21 | #include "app/loadBalancing/sortingAlgorithm/BaseSorting.h" 22 | #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h" 23 | 24 | namespace task_offloading { 25 | class ComputationTime : public BaseSorting { 26 | public: 27 | ComputationTime(); 28 | virtual ~ComputationTime(); 29 | std::list sort(const std::map &map) override; 30 | }; 31 | } 32 | 33 | #endif /* APP_LOADBALANCING_SORTINGALGORITHM_COMPUTATIONTIME_H_ */ 34 | -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/ComputationTime.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 task_offloading.app.loadBalancing.sortingAlgorithm; 17 | 18 | simple ComputationTime like ISorting 19 | { 20 | @class(task_offloading::ComputationTime); 21 | } -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/FIFO.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 "FIFO.h" 17 | 18 | using namespace task_offloading; 19 | 20 | Define_Module(task_offloading::FIFO); 21 | 22 | FIFO::FIFO() { 23 | // 24 | } 25 | 26 | FIFO::~FIFO() { 27 | // 28 | } 29 | 30 | bool cmpFIFO(std::pair &a, std::pair &b) { 31 | return a.second.getCreatedAt() < b.second.getCreatedAt(); 32 | } 33 | 34 | std::list FIFO::sort(const std::map &map) { 35 | std::list l; 36 | 37 | std::vector> pairVector; 38 | 39 | // Copy the IDs of the map into the vector 40 | for (auto &it : map) { 41 | pairVector.push_back(it); 42 | } 43 | 44 | // Sorting the array with the cmp function defined above 45 | std::sort(pairVector.begin(), pairVector.end(), cmpFIFO); 46 | 47 | // Fill the list with ordered IDs 48 | for (auto &it : pairVector) { 49 | l.push_back(it.first); 50 | } 51 | 52 | return l; 53 | } 54 | -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/FIFO.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 APP_LOADBALANCING_SORTINGALGORITHM_FIFO_H_ 17 | #define APP_LOADBALANCING_SORTINGALGORITHM_FIFO_H_ 18 | 19 | #include "veins/veins.h" 20 | #include "app/vehiclesHandling/HelperVehicleInfo.h" 21 | #include "app/loadBalancing/sortingAlgorithm/BaseSorting.h" 22 | #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h" 23 | 24 | namespace task_offloading { 25 | class FIFO : public BaseSorting { 26 | public: 27 | FIFO(); 28 | virtual ~FIFO(); 29 | std::list sort(const std::map &map) override; 30 | }; 31 | } 32 | 33 | #endif /* APP_LOADBALANCING_SORTINGALGORITHM_FIFO_H_ */ 34 | -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/FIFO.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 task_offloading.app.loadBalancing.sortingAlgorithm; 17 | 18 | simple FIFO like ISorting 19 | { 20 | @class(task_offloading::FIFO); 21 | } -------------------------------------------------------------------------------- /src/app/loadBalancing/sortingAlgorithm/ISorting.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 task_offloading.app.loadBalancing.sortingAlgorithm; 17 | 18 | moduleinterface ISorting 19 | { 20 | } -------------------------------------------------------------------------------- /src/app/messages/AckMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | 20 | namespace task_offloading; 21 | 22 | packet AckMessage extends veins::BaseFrame1609_4 { 23 | int hostIndex; 24 | int taskID; 25 | int partitionID; 26 | } 27 | -------------------------------------------------------------------------------- /src/app/messages/AckTimerMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | import ResponseMessage; 20 | 21 | namespace task_offloading; 22 | 23 | packet AckTimerMessage extends veins::BaseFrame1609_4 { 24 | ResponseMessage* data; 25 | } 26 | -------------------------------------------------------------------------------- /src/app/messages/AvailabilityMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | 20 | namespace task_offloading; 21 | 22 | packet AvailabilityMessage extends veins::BaseFrame1609_4 { 23 | int hostID; 24 | string index; 25 | double availableLoad; 26 | double cpuFreq; 27 | veins::LAddress::L2Type senderAddress = -1; 28 | double vehicleAngle; 29 | double vehicleSpeed; 30 | } 31 | -------------------------------------------------------------------------------- /src/app/messages/ComputationTimerMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | import DataMessage; 20 | 21 | namespace task_offloading; 22 | 23 | packet ComputationTimerMessage extends veins::BaseFrame1609_4 { 24 | DataMessage* data; 25 | } 26 | -------------------------------------------------------------------------------- /src/app/messages/DataMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | 20 | namespace task_offloading; 21 | 22 | packet DataMessage extends veins::BaseFrame1609_4 { 23 | double loadToProcess; 24 | double computationTime; 25 | int hostIndex; 26 | int partitionId; 27 | int taskId; 28 | int loadBalancingId; 29 | int cpi; 30 | veins::LAddress::L2Type senderAddress = -1; 31 | } 32 | -------------------------------------------------------------------------------- /src/app/messages/HelpMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | 20 | namespace task_offloading; 21 | 22 | packet HelpMessage extends veins::BaseFrame1609_4 { 23 | int vehicleIndex; 24 | int id; 25 | double minimumLoadRequested; 26 | } 27 | -------------------------------------------------------------------------------- /src/app/messages/LoadBalanceTimerMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | 20 | namespace task_offloading; 21 | 22 | packet LoadBalanceTimerMessage extends veins::BaseFrame1609_4 { 23 | simtime_t simulationTime; 24 | } 25 | -------------------------------------------------------------------------------- /src/app/messages/ResponseMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | 20 | namespace task_offloading; 21 | 22 | packet ResponseMessage extends veins::BaseFrame1609_4 { 23 | int hostIndex; 24 | bool stillAvailable; 25 | double dataComputed; 26 | double timeToCompute; 27 | int taskID; 28 | int partitionID; 29 | } 30 | -------------------------------------------------------------------------------- /src/app/messages/UpdateAvailabilityMessage.msg: -------------------------------------------------------------------------------- 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 | import veins.base.utils.Coord; 17 | import veins.modules.messages.BaseFrame1609_4; 18 | import veins.base.utils.SimpleAddress; 19 | 20 | namespace task_offloading; 21 | 22 | packet UpdateAvailabilityMessage extends veins::BaseFrame1609_4 { 23 | string availability; 24 | } 25 | -------------------------------------------------------------------------------- /src/app/messagesHandling/AvailabilityMessageHandler.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 "app/TaskGenerator.h" 17 | 18 | using namespace task_offloading; 19 | 20 | void TaskGenerator::handleAvailabilityMessage(AvailabilityMessage* availabilityMessage) 21 | { 22 | // Check the bus state 23 | int currentBusState = busState.getCurrentState(); 24 | 25 | if (findHost()->getIndex() == busIndex && currentBusState == 1) { 26 | // Color the bus that received help 27 | findHost()->getDisplayString().setTagArg("i", 1, "green"); 28 | std::string currentHostIndex = availabilityMessage->getIndex() + std::to_string(availabilityMessage->getHostID()); 29 | double currentLoad = availabilityMessage->getAvailableLoad(); 30 | double CPUFreq = availabilityMessage->getCpuFreq(); 31 | veins::LAddress::L2Type address = availabilityMessage->getSenderAddress(); 32 | double vehicleAngle = availabilityMessage->getVehicleAngle(); 33 | double vehicleSpeed = availabilityMessage->getVehicleSpeed(); 34 | 35 | helpers[availabilityMessage->getHostID()] = HelperVehicleInfo(currentHostIndex, currentLoad, CPUFreq, address); 36 | helpers[availabilityMessage->getHostID()].setVehicleAngle(vehicleAngle); 37 | helpers[availabilityMessage->getHostID()].setVehicleSpeed(vehicleSpeed); 38 | helpers[availabilityMessage->getHostID()].setTaskCpi(tasks[0].getCpi()); 39 | 40 | int previousAvailability = tasks[0].getAvailableReceivedCounter(); 41 | previousAvailability++; 42 | tasks[0].setAvailableReceivedCounter(previousAvailability); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/app/messagesHandling/DataMessageHandler.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 "app/Worker.h" 17 | #include "app/messages/AckTimerMessage_m.h" 18 | 19 | using namespace task_offloading; 20 | 21 | void Worker::handleDataMessage(DataMessage* dataMessage) 22 | { 23 | // Emit the signal for have received data message 24 | emit(stopDataMessages, dataMessage->getHostIndex()); 25 | 26 | // Calculate time for computation 27 | double CPI = dataMessage->getCpi(); 28 | double I = dataMessage->getLoadToProcess(); 29 | double CR = cpuFreq; 30 | 31 | double timeToCompute = CPI * I * (1 / CR); 32 | 33 | // Check if I'm the vehicle designated for computation and if the data is different 34 | if (dataMessage->getHostIndex() == findHost()->getIndex()) { 35 | // Color the vehicle in red when computing 36 | findHost()->getDisplayString().setTagArg("i", 1, "red"); 37 | 38 | // Update the partition ID 39 | currentDataPartitionId = dataMessage->getPartitionId(); 40 | 41 | // Update if I'll be still available 42 | stillAvailableProbability = par("stillAvailableProbability").doubleValue() > par("stillAvailableThreshold").doubleValue(); 43 | 44 | // Prepare the response message 45 | ResponseMessage* responseMessage = new ResponseMessage(); 46 | 47 | // Populate the response message 48 | 49 | // If useAcks is active then send the message with L2Address 50 | // otherwise send it without address to use the manual secure protocol 51 | if (par("useAcks").boolValue()) { 52 | populateWSM(responseMessage, dataMessage->getSenderAddress()); 53 | } else { 54 | populateWSM(responseMessage); 55 | } 56 | 57 | // Populate other fields 58 | responseMessage->setHostIndex(dataMessage->getHostIndex()); 59 | responseMessage->setStillAvailable(stillAvailableProbability); 60 | responseMessage->setDataComputed(dataMessage->getLoadToProcess()); 61 | responseMessage->setTimeToCompute(timeToCompute); 62 | responseMessage->setTaskID(dataMessage->getTaskId()); 63 | responseMessage->setPartitionID(dataMessage->getPartitionId()); 64 | responseMessage->addByteLength(dataMessage->getLoadToProcess()); 65 | 66 | // Schedule the response message 67 | scheduleAt(simTime() + timeToCompute, responseMessage); 68 | 69 | // Generate ACK timer if parameter useAcks is false 70 | // to achieve secure protocol manually and if I'm not still available 71 | if (!(par("useAcks").boolValue()) && !(stillAvailableProbability)) { 72 | AckTimerMessage* ackTimerMessage = new AckTimerMessage(); 73 | populateWSM(ackTimerMessage); 74 | ackTimerMessage->setData(responseMessage); 75 | 76 | // Calculate time to file transmission 77 | double transferTime = 10.0; 78 | 79 | scheduleAt(simTime() + timeToCompute + transferTime + par("ackMessageThreshold").doubleValue(), ackTimerMessage); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/app/messagesHandling/HelpMessageHandler.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 "app/Worker.h" 17 | 18 | using namespace task_offloading; 19 | 20 | void Worker::handleHelpMessage(HelpMessage* helpMessage) 21 | { 22 | // I've received an help request from bus 23 | 24 | // Emit the help message received 25 | emit(stopHelp, simTime()); 26 | 27 | // First check if I met requirements for the bus 28 | double minimumLoadRequested = helpMessage->getMinimumLoadRequested(); 29 | 30 | // Check my current load 31 | double currentVehicleLoad = par("randomVehicleFreeLoadPercentage").doubleValue() * par("commonVehicleLoad").doubleValue(); 32 | 33 | // Emit the signal for my current load 34 | emit(availableMessageLoad, currentVehicleLoad); 35 | 36 | // Check my current CPU freq 37 | double CPUFreq = par("randomVehicleCpuFreq").doubleValue(); 38 | 39 | // Set my CPU freq 40 | cpuFreq = CPUFreq; 41 | 42 | // If I met requirements send an available message 43 | if (currentVehicleLoad >= minimumLoadRequested) { 44 | // Color the vehicle icon in blue 45 | findHost()->getDisplayString().setTagArg("i", 1, "blue"); 46 | 47 | // Prepare the availability message 48 | AvailabilityMessage* available = new AvailabilityMessage(); 49 | 50 | // Populate the message 51 | populateWSM(available); 52 | available->setHostID(findHost()->getIndex()); 53 | available->setIndex(findHost()->getName()); 54 | available->setAvailableLoad(currentVehicleLoad); 55 | available->setCpuFreq(cpuFreq); 56 | available->setVehicleAngle(traciVehicle->getAngle()); 57 | available->setVehicleSpeed(traciVehicle->getSpeed()); 58 | 59 | // Schedule the ok message 60 | scheduleAt(simTime() + par("vehicleAvailabilityMessageTime").doubleValue(), available); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/app/messagesHandling/ResponseMessageHandler.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 "app/TaskGenerator.h" 17 | #include "app/messages/AckMessage_m.h" 18 | 19 | using namespace task_offloading; 20 | 21 | void TaskGenerator::handleResponseMessage(ResponseMessage* responseMessage) 22 | { 23 | // Search the vehicle in the map 24 | auto found = helpers.find(responseMessage->getHostIndex()); 25 | 26 | // If the auto is found in the map and the partition id coincide with response message then 27 | // handle the response otherwise get rid of it 28 | if (found != helpers.end() && helpers[responseMessage->getHostIndex()].getDataPartitionId() == responseMessage->getPartitionID()) { 29 | // Emit signal for having received response 30 | emit(stopResponseMessages, responseMessage->getHostIndex()); 31 | 32 | // Update the data partiton id into the helpers map 33 | helpers[responseMessage->getHostIndex()].setDataPartitionId(-1); 34 | 35 | // Remove the data that the vehicle has computed 36 | double localData = tasks[0].getData() - responseMessage->getDataComputed(); 37 | tasks[0].setData(localData); 38 | 39 | // If there's no more data then emit signal for task finished 40 | if (localData <= 0) { 41 | emit(stopTask, simTime()); 42 | } 43 | 44 | // Increment the task responses received 45 | int responseReceived = tasks[0].getResponseReceivedCounter(); 46 | responseReceived++; 47 | tasks[0].setResponseReceivedCounter(responseReceived); 48 | 49 | // Get the availability received 50 | int vehiclesAvailable = tasks[0].getAvailableReceivedCounter(); 51 | 52 | // Get the load balancing id 53 | int loadBalanceId = tasks[0].getLoadBalancingId(); 54 | 55 | // If the vehicle is not available anymore erase it from the map 56 | // and from the list 57 | if (responseMessage->getStillAvailable() == false) { 58 | helpers.erase(responseMessage->getHostIndex()); 59 | helpersOrderedList.remove(responseMessage->getHostIndex()); 60 | 61 | // Schedule the ack message 62 | if (!(par("useAcks").boolValue())) { 63 | // Send ACK message to the host 64 | AckMessage* ackMessage = new AckMessage(); 65 | populateWSM(ackMessage); 66 | ackMessage->setHostIndex(responseMessage->getHostIndex()); 67 | ackMessage->setTaskID(responseMessage->getTaskID()); 68 | ackMessage->setPartitionID(responseMessage->getPartitionID()); 69 | scheduleAt(simTime(), ackMessage); 70 | } 71 | } 72 | 73 | // If there are more vehicles available and I've received all responses 74 | // then restart load balancing 75 | if (helpers.size() > 0 && localData > 0 && vehiclesAvailable == responseReceived) { 76 | // Increment load balance id 77 | loadBalanceId++; 78 | tasks[0].setLoadBalancingId(loadBalanceId); 79 | 80 | // Set the new availability 81 | int newAvailability = helpers.size(); 82 | tasks[0].setAvailableReceivedCounter(newAvailability); 83 | 84 | // Set the responses received to 0 85 | tasks[0].setResponseReceivedCounter(0); 86 | 87 | balanceLoad(); 88 | } 89 | 90 | // If there are no more vehicles but still more data to compute then take the bus 91 | // back in help status 92 | if (helpers.size() == 0 && localData > 0 && vehiclesAvailable == responseReceived) { 93 | // Color the bus in white when it has no more vehicles 94 | findHost()->getDisplayString().setTagArg("i", 1, "white"); 95 | 96 | // Set the new availability 97 | tasks[0].setAvailableReceivedCounter(0); 98 | 99 | // Set the responses received to 0 100 | tasks[0].setResponseReceivedCounter(0); 101 | 102 | // Change it's status in help 103 | busState.setState(new Help); 104 | } 105 | } else if (tasks[0].getData() <= 0) { 106 | // If data <= 0 and I receive a response then send ack to the vehicle 107 | helpers.erase(responseMessage->getHostIndex()); 108 | helpersOrderedList.remove(responseMessage->getHostIndex()); 109 | 110 | // Schedule the ack message 111 | if (!(par("useAcks").boolValue())) { 112 | // Send ACK message to the host 113 | AckMessage* ackMessage = new AckMessage(); 114 | populateWSM(ackMessage); 115 | ackMessage->setHostIndex(responseMessage->getHostIndex()); 116 | ackMessage->setTaskID(responseMessage->getTaskID()); 117 | ackMessage->setPartitionID(responseMessage->getPartitionID()); 118 | scheduleAt(simTime(), ackMessage); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/app/secureProtocol/SendAgainDataMessage.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 "app/TaskGenerator.h" 17 | #include "app/messages/ComputationTimerMessage_m.h" 18 | 19 | using namespace task_offloading; 20 | 21 | void TaskGenerator::sendAgainData(const DataMessage* data) 22 | { 23 | // Search the vehicle in the map 24 | auto found = helpers.find(data->getHostIndex()); 25 | 26 | // Check load balancing id 27 | bool loadBalancingIdCheck = tasks[0].getLoadBalancingId() == data->getLoadBalancingId(); 28 | 29 | // If the vehicle is found check if I've received the data from it 30 | if (found != helpers.end() && (loadBalancingIdCheck)) { 31 | // Check the data partition id 32 | bool checkDataPartitionId = helpers[data->getHostIndex()].getDataPartitionId() != -1; 33 | 34 | if (checkDataPartitionId) { 35 | // Send the duplicate data message 36 | sendDown(data->dup()); 37 | 38 | // Restart again the timer 39 | ComputationTimerMessage* computationTimerMessage = new ComputationTimerMessage(); 40 | populateWSM(computationTimerMessage); 41 | computationTimerMessage->setData(data->dup()); 42 | 43 | double transferTime = 10.0; 44 | 45 | scheduleAt(simTime() + transferTime + data->getComputationTime() + par("dataComputationThreshold").doubleValue(), computationTimerMessage); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/secureProtocol/SendAgainResponseMessage.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 "app/Worker.h" 17 | #include "app/messages/AckTimerMessage_m.h" 18 | 19 | using namespace task_offloading; 20 | 21 | void Worker::sendAgainResponse(const ResponseMessage* response) 22 | { 23 | if (currentDataPartitionId == response->getPartitionID()) { 24 | // Schedule the new duplicate response message 25 | scheduleAt(simTime() + response->getTimeToCompute(), response->dup()); 26 | 27 | // Restart the ACK timer 28 | AckTimerMessage* ackTimerMessage = new AckTimerMessage(); 29 | populateWSM(ackTimerMessage); 30 | ackTimerMessage->setData(response->dup()); 31 | 32 | double transferTime = 10.0; 33 | 34 | scheduleAt(simTime() + transferTime + response->getTimeToCompute() + par("ackMessageThreshold").doubleValue(), ackTimerMessage); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/app/vehiclesHandling/HelperVehicleInfo.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 "HelperVehicleInfo.h" 17 | 18 | using namespace task_offloading; 19 | 20 | HelperVehicleInfo::HelperVehicleInfo() { 21 | this->index = "auto0"; 22 | this->hostCurrentLoad = 0; 23 | this->hostCPUFreq = 0; 24 | this->createdAt = simTime(); 25 | this->address = 0; 26 | this->dataPartitionId = -1; 27 | } 28 | 29 | HelperVehicleInfo::HelperVehicleInfo(std::string index, double load, double freq, veins::LAddress::L2Type address) { 30 | this->index = index; 31 | this->hostCurrentLoad = load; 32 | this->hostCPUFreq = freq; 33 | this->createdAt = simTime(); 34 | this->address = address; 35 | this->dataPartitionId = -1; 36 | } 37 | 38 | HelperVehicleInfo::~HelperVehicleInfo() { 39 | // 40 | } 41 | 42 | /** 43 | * @returns Current index of a vehicle 44 | */ 45 | std::string HelperVehicleInfo::getIndex() { 46 | return this->index; 47 | } 48 | 49 | /** 50 | * @returns Current load of a vehicle in MB 51 | */ 52 | double HelperVehicleInfo::getCurrentLoad() { 53 | return this->hostCurrentLoad; 54 | } 55 | 56 | /** 57 | * @returns Current CPU frequency of a vehicle in GHz 58 | */ 59 | double HelperVehicleInfo::getCPUFreq() { 60 | return this->hostCPUFreq; 61 | } 62 | 63 | /** 64 | * @returns Timestamp corresponding to when the object is created in s 65 | */ 66 | simtime_t HelperVehicleInfo::getCreatedAt() { 67 | return this->createdAt; 68 | } 69 | 70 | /** 71 | * @returns The L2 address of a vehicle 72 | */ 73 | veins::LAddress::L2Type HelperVehicleInfo::getAddress() { 74 | return this->address; 75 | } 76 | 77 | /** 78 | * @returns The angle of a vehicle in degrees 79 | */ 80 | double HelperVehicleInfo::getVehicleAngle() { 81 | return this->vehicleAngle; 82 | } 83 | 84 | /** 85 | * @returns The current data partition id of the vehicle computation 86 | */ 87 | int HelperVehicleInfo::getDataPartitionId() { 88 | return this->dataPartitionId; 89 | } 90 | 91 | /** 92 | * @returns The current task cpi -> useful when calculating total compute time 93 | */ 94 | int HelperVehicleInfo::getTaskCpi() { 95 | return this->taskCpi; 96 | } 97 | 98 | /** 99 | * @returns The speed of a vehicle in m/s 100 | */ 101 | double HelperVehicleInfo::getVehicleSpeed() { 102 | return this->vehicleSpeed; 103 | } 104 | 105 | /** 106 | * Set the current index of a vehicle 107 | * 108 | * @param newIndex The new index of a vehicle 109 | */ 110 | void HelperVehicleInfo::setIndex(std::string index) { 111 | this->index = index; 112 | } 113 | 114 | /** 115 | * Set the current load of a vehicle 116 | * 117 | * @param newLoad The new load of a vehicle 118 | */ 119 | void HelperVehicleInfo::setCurrentLoad(double newLoad) { 120 | this->hostCurrentLoad = newLoad; 121 | } 122 | 123 | /** 124 | * Set the current CPU frequency of a vehicle 125 | * 126 | * @param newFreq The new frequency of a vehicle 127 | */ 128 | void HelperVehicleInfo::setCPUFreq(double newFreq) { 129 | this->hostCPUFreq = newFreq; 130 | } 131 | 132 | /** 133 | * Set the creation time of the object 134 | * 135 | * @param newTime Timestamp when object is created 136 | */ 137 | void HelperVehicleInfo::setCreatedAt(simtime_t newTime) { 138 | this->createdAt = newTime; 139 | } 140 | 141 | /** 142 | * Set the current L2 address of a vehicle 143 | * 144 | * @param newAddress The new address of a vehicle 145 | */ 146 | void HelperVehicleInfo::setAddress(veins::LAddress::L2Type newAddress) { 147 | this->address = newAddress; 148 | } 149 | 150 | /** 151 | * Set the current angle of a vehicle in degrees 152 | * 153 | * @param newAddress The new angle in degrees of a vehicle 154 | */ 155 | void HelperVehicleInfo::setVehicleAngle(double newAngle) { 156 | this->vehicleAngle = newAngle; 157 | } 158 | 159 | /** 160 | * Set the current data partition id of the vehicle computation 161 | * 162 | * @param newPartitionId The new id of a data partition 163 | */ 164 | void HelperVehicleInfo::setDataPartitionId(int newPartitionId) { 165 | this->dataPartitionId = newPartitionId; 166 | } 167 | 168 | /** 169 | * Set the current cpi of the task 170 | * 171 | * @param newCpi The new cpi of the task -> useful when calculating total compute time 172 | */ 173 | void HelperVehicleInfo::setTaskCpi(int newCpi) { 174 | this->taskCpi = newCpi; 175 | } 176 | 177 | /** 178 | * Set the current speed of a vehicle in m/s 179 | * 180 | * @param newSpeed The new current speed of a vehicle 181 | */ 182 | void HelperVehicleInfo::setVehicleSpeed(double newSpeed) { 183 | this->vehicleSpeed = newSpeed; 184 | } 185 | 186 | /** 187 | * This method calculate the toal computation time of a task 188 | * considering the current load and the CPU frequency of a vehicle 189 | * 190 | * @param CPI Clock per instructions 191 | * @returns The total computation time for a task 192 | */ 193 | double HelperVehicleInfo::getTotalComputationTime(int CPI) { 194 | return (CPI * this->hostCurrentLoad * (1 / this->hostCPUFreq)); 195 | } 196 | -------------------------------------------------------------------------------- /src/app/vehiclesHandling/HelperVehicleInfo.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 APP_VEHICLESHANDLING_HELPERVEHICLEINFO_H_ 17 | #define APP_VEHICLESHANDLING_HELPERVEHICLEINFO_H_ 18 | 19 | #include "veins/veins.h" 20 | #include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h" 21 | 22 | namespace task_offloading { 23 | class HelperVehicleInfo { 24 | private: 25 | std::string index; 26 | double hostCurrentLoad; 27 | double hostCPUFreq; 28 | simtime_t createdAt; 29 | veins::LAddress::L2Type address; 30 | double vehicleSpeed; 31 | double vehicleAngle; 32 | int dataPartitionId; 33 | int taskCpi; 34 | 35 | public: 36 | HelperVehicleInfo(); 37 | HelperVehicleInfo(std::string index, double load, double freq, veins::LAddress::L2Type address); 38 | virtual ~HelperVehicleInfo(); 39 | std::string getIndex(); 40 | double getCurrentLoad(); 41 | double getCPUFreq(); 42 | simtime_t getCreatedAt(); 43 | veins::LAddress::L2Type getAddress(); 44 | double getVehicleAngle(); 45 | int getDataPartitionId(); 46 | int getTaskCpi(); 47 | double getVehicleSpeed(); 48 | void setIndex(std::string index); 49 | void setCurrentLoad(double newLoad); 50 | void setCPUFreq(double newFreq); 51 | void setCreatedAt(simtime_t newTime); 52 | void setAddress(veins::LAddress::L2Type newAddress); 53 | void setVehicleAngle(double newAngle); 54 | void setDataPartitionId(int newPartitionId); 55 | void setTaskCpi(int newCpi); 56 | void setVehicleSpeed(double newSpeed); 57 | double getTotalComputationTime(int CPI); 58 | }; 59 | } 60 | 61 | #endif /* APP_VEHICLESHANDLING_HELPERVEHICLEINFO_H_ */ 62 | -------------------------------------------------------------------------------- /src/app/vehiclesHandling/VehicleHandler.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 "app/TaskGenerator.h" 17 | #include "app/messages/LoadBalanceTimerMessage_m.h" 18 | 19 | using namespace task_offloading; 20 | 21 | void TaskGenerator::vehicleHandler() 22 | { 23 | // Get the timer for the first help message 24 | bool timerForFirstHelpMessage = simTime() > par("randomTimeFirstHelpMessage").doubleValue(); 25 | // Check the bus state 26 | int currentBusState = busState.getCurrentState(); 27 | // Check if there's more data 28 | bool moreDataToLoad = tasks[0].getData() > 0; 29 | // Check if it's the second (or more) help message 30 | bool isFirstHelpMessage = tasks[0].getHelpReceivedCounter() == 0; 31 | 32 | // Check if we reach the time of the first help message 33 | if (timerForFirstHelpMessage && (currentBusState == 0) && moreDataToLoad && helpers.size() == 0) { 34 | // If it's the first message then initialize the task 35 | if (isFirstHelpMessage) { 36 | tasks[0] = Task(0, par("computationLoad").doubleValue(), par("minimumVehicleLoadRequested").doubleValue(), 3); 37 | } 38 | 39 | // Color the bus icon in red 40 | findHost()->getDisplayString().setTagArg("i", 1, "red"); 41 | 42 | // Prepare the help message 43 | HelpMessage* helpMessage = new HelpMessage(); 44 | 45 | // Populate the message 46 | populateWSM(helpMessage); 47 | helpMessage->setId(tasks[0].getHelpReceivedCounter()); 48 | helpMessage->setVehicleIndex(busIndex); 49 | helpMessage->setMinimumLoadRequested(tasks[0].getMinimumLoadRequested()); 50 | 51 | // Emit signal for start help message 52 | emit(startHelp, simTime()); 53 | 54 | // Send the message in broadcast 55 | sendDown(helpMessage); 56 | 57 | if (tasks[0].getHelpReceivedCounter() == 0) { 58 | emit(startTask, simTime()); 59 | } 60 | 61 | // Start bus waiting timer for accepting availability messages 62 | LoadBalanceTimerMessage* timerForLoadBalancing = new LoadBalanceTimerMessage(); 63 | 64 | // Save the actual simtime for future help messages 65 | simtime_t simTimeActual = simTime(); 66 | 67 | // Populate the message 68 | populateWSM(timerForLoadBalancing); 69 | timerForLoadBalancing->setSimulationTime(simTimeActual); 70 | 71 | // Change the load balancing state 72 | busState.setState(new LoadBalancing); 73 | 74 | // Increment the counter for help messages 75 | int helpCounter = tasks[0].getHelpReceivedCounter(); 76 | helpCounter++; 77 | tasks[0].setHelpReceivedCounter(helpCounter); 78 | 79 | // Schedule the message -> simTime + availability msgs threshold 80 | scheduleAt(simTimeActual + par("busWaitingTimeForAvailability").doubleValue(), timerForLoadBalancing); 81 | } else if (tasks[0].getData() <= 0) { 82 | // Color the bus in white when computation ends 83 | findHost()->getDisplayString().setTagArg("i", 1, "white"); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/package.ned: -------------------------------------------------------------------------------- 1 | package task_offloading; 2 | 3 | @license(LGPL); 4 | -------------------------------------------------------------------------------- /src/task_offloading_dbg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connets/task_offloading/ee1f9916aebdcc5fd3ff039fdc5abf8ff6acebc8/src/task_offloading_dbg --------------------------------------------------------------------------------