Skip to content

Commit 87cfd86

Browse files
committed
higher frequency simulation in omnet++ and a script to run act on ARM
1 parent 5c2b825 commit 87cfd86

21 files changed

Lines changed: 780 additions & 45 deletions

File tree

examples/omnetpp_burst/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ A GitHub Actions workflow is included that:
6767
- Runs the simulation demo
6868
- Can be extended for result validation
6969

70+
7071
## OMNeT++ Resources
7172

7273
- [Documentation](https://doc.omnetpp.org/)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.x'
23+
24+
- name: Cache OMNeT++ installation
25+
uses: actions/cache@v3
26+
with:
27+
path: |
28+
~/.opp_env
29+
~/.cache/opp_env
30+
key: ${{ runner.os }}-omnetpp-6.2.0-${{ hashFiles('**/omnetpp.ini') }}
31+
restore-keys: |
32+
${{ runner.os }}-omnetpp-6.2.0-
33+
${{ runner.os }}-omnetpp-
34+
35+
- name: Install OMNeT++ via opp_env
36+
run: |
37+
pip install opp-env
38+
opp_env init
39+
opp_env install omnetpp-6.2.0
40+
shell: bash
41+
42+
- name: Configure
43+
run: |
44+
mkdir -p build
45+
cd build
46+
cmake ..
47+
48+
- name: Build
49+
run: |
50+
cd build
51+
cmake --build .
52+
53+
- name: Run Demo Simulation
54+
run: |
55+
cd build
56+
# Determine binary name: {project}.omnetpp.{os}
57+
OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
58+
PROJECT_NAME=$(grep -o 'project([^)]*)' ../CMakeLists.txt | head -1 | sed 's/project(\([^ ]*\).*/\1/')
59+
BINARY="${PROJECT_NAME}.omnetpp.${OS_NAME}"
60+
# Run simulation with config from omnetpp.ini
61+
if [ -f "../omnetpp.ini" ]; then
62+
./"${BINARY}" -u Cmdenv -c General -n ..
63+
fi
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(HighFreqNetwork)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
# Detect OS for binary naming: {example}.omnetpp.{os}
8+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
9+
set(OS_SUFFIX "darwin")
10+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
11+
set(OS_SUFFIX "linux")
12+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
13+
set(OS_SUFFIX "exe")
14+
else()
15+
set(OS_SUFFIX "bin")
16+
endif()
17+
18+
# Find OMNeT++ using the CMake module
19+
# First, try the modern find_package approach
20+
find_package(OmnetPP QUIET)
21+
22+
if(NOT OmnetPP_FOUND)
23+
# Fallback: manually find OMNeT++ using environment variable
24+
if(NOT DEFINED ENV{OMNETPP_ROOT})
25+
message(FATAL_ERROR "OMNETPP_ROOT environment variable is not set. Please source OMNeT++ setenv script.")
26+
endif()
27+
28+
set(OMNETPP_ROOT $ENV{OMNETPP_ROOT})
29+
list(APPEND CMAKE_MODULE_PATH "${OMNETPP_ROOT}/misc/cmake")
30+
31+
# Try again with the module path
32+
find_package(OmnetPP QUIET)
33+
34+
if(NOT OmnetPP_FOUND)
35+
# Last resort: manual library finding
36+
set(OMNETPP_INCLUDE_DIRS ${OMNETPP_ROOT}/include)
37+
set(OMNETPP_LIB_DIR ${OMNETPP_ROOT}/lib)
38+
39+
# Find all required OMNeT++ libraries
40+
find_library(OMNETPP_MAIN_LIB oppmain PATHS ${OMNETPP_LIB_DIR} REQUIRED NO_DEFAULT_PATH)
41+
find_library(OMNETPP_CMDENV_LIB oppcmdenv PATHS ${OMNETPP_LIB_DIR} REQUIRED NO_DEFAULT_PATH)
42+
find_library(OMNETPP_ENVIR_LIB oppenvir PATHS ${OMNETPP_LIB_DIR} REQUIRED NO_DEFAULT_PATH)
43+
find_library(OMNETPP_SIM_LIB oppsim PATHS ${OMNETPP_LIB_DIR} REQUIRED NO_DEFAULT_PATH)
44+
find_library(OMNETPP_COMMON_LIB oppcommon PATHS ${OMNETPP_LIB_DIR} REQUIRED NO_DEFAULT_PATH)
45+
46+
# Libraries must be in this order: main (contains main()), cmdenv, envir, sim, common
47+
set(OMNETPP_LIBRARIES
48+
${OMNETPP_MAIN_LIB}
49+
${OMNETPP_CMDENV_LIB}
50+
${OMNETPP_ENVIR_LIB}
51+
${OMNETPP_SIM_LIB}
52+
${OMNETPP_COMMON_LIB}
53+
dl
54+
pthread
55+
)
56+
endif()
57+
endif()
58+
59+
# Source files
60+
set(SOURCES
61+
Consumer.cc
62+
Producer.cc
63+
)
64+
65+
# Create executable
66+
add_executable(HighFreqNetwork ${SOURCES})
67+
68+
# Set output binary name: {example}.omnetpp.{os}
69+
set_target_properties(HighFreqNetwork PROPERTIES
70+
OUTPUT_NAME "HighFreqNetwork.omnetpp.${OS_SUFFIX}"
71+
)
72+
73+
# Link OMNeT++ libraries
74+
if(TARGET OmnetPP::main)
75+
# Use modern CMake targets if available
76+
target_link_libraries(HighFreqNetwork PRIVATE
77+
OmnetPP::main
78+
OmnetPP::cmdenv
79+
OmnetPP::envir
80+
OmnetPP::sim
81+
)
82+
elseif(TARGET OmnetPP::omnetpp)
83+
target_link_libraries(HighFreqNetwork PRIVATE OmnetPP::omnetpp)
84+
else()
85+
# Fallback to manually found libraries
86+
target_link_libraries(HighFreqNetwork PRIVATE
87+
${OMNETPP_LIBRARIES}
88+
)
89+
target_include_directories(HighFreqNetwork PRIVATE
90+
${OMNETPP_INCLUDE_DIRS}
91+
${CMAKE_CURRENT_SOURCE_DIR}
92+
)
93+
# Ensure shared libraries are linked properly
94+
target_link_options(HighFreqNetwork PRIVATE
95+
-Wl,--no-as-needed
96+
)
97+
endif()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Generated from ActorSimulation DSL
2+
// Actor: consumer
3+
4+
#include "Consumer.h"
5+
6+
Define_Module(Consumer);
7+
8+
void Consumer::initialize() {
9+
sendCount = 0;
10+
selfMsg = nullptr;
11+
// No send pattern defined
12+
}
13+
14+
void Consumer::handleMessage(cMessage *msg) {
15+
if (msg->isSelfMessage()) {
16+
// No send pattern
17+
18+
} else {
19+
// Handle received message
20+
// EV << "Received message: " << msg->getName() << "\n";
21+
delete msg;
22+
}
23+
}
24+
25+
void Consumer::finish() {
26+
// EV << "Consumer sent " << sendCount << " messages\n";
27+
if (selfMsg != nullptr) {
28+
cancelAndDelete(selfMsg);
29+
selfMsg = nullptr;
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Generated from ActorSimulation DSL
2+
// Actor: consumer
3+
4+
#ifndef CONSUMER_H
5+
#define CONSUMER_H
6+
7+
#include <omnetpp.h>
8+
9+
using namespace omnetpp;
10+
11+
class Consumer : public cSimpleModule {
12+
private:
13+
cMessage *selfMsg;
14+
int sendCount;
15+
16+
protected:
17+
virtual void initialize() override;
18+
virtual void handleMessage(cMessage *msg) override;
19+
virtual void finish() override;
20+
};
21+
22+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Generated from ActorSimulation DSL
2+
3+
simple Consumer {
4+
gates:
5+
input in;}
6+
7+
8+
simple Producer {
9+
gates:
10+
output out[1];}
11+
12+
13+
network HighFreqNetwork {
14+
submodules:
15+
consumer: Consumer;
16+
producer: Producer;
17+
connections:
18+
producer.out[0] --> consumer.in;
19+
}
20+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Generated from ActorSimulation DSL
2+
// Actor: producer
3+
4+
#include "Producer.h"
5+
6+
Define_Module(Producer);
7+
8+
void Producer::initialize() {
9+
sendCount = 0;
10+
selfMsg = nullptr;
11+
selfMsg = new cMessage("selfMsg");
12+
scheduleAt(simTime() + 0.001, selfMsg);
13+
}
14+
15+
void Producer::handleMessage(cMessage *msg) {
16+
if (msg->isSelfMessage()) {
17+
// Send messages
18+
// EV << getName() << ": Processing message\n";
19+
for (int i = 0; i < 1; i++) {
20+
cMessage *outMsg = new cMessage("msg");
21+
send(outMsg, "out", i);
22+
sendCount++;
23+
}
24+
// EV << getName() << ": Sent " << 1 << " messages\n";
25+
26+
// Reschedule
27+
scheduleAt(simTime() + 0.001, msg);
28+
29+
} else {
30+
// Handle received message
31+
// EV << "Received message: " << msg->getName() << "\n";
32+
delete msg;
33+
}
34+
}
35+
36+
void Producer::finish() {
37+
// EV << "Producer sent " << sendCount << " messages\n";
38+
if (selfMsg != nullptr) {
39+
cancelAndDelete(selfMsg);
40+
selfMsg = nullptr;
41+
}
42+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Generated from ActorSimulation DSL
2+
// Actor: producer
3+
4+
#ifndef PRODUCER_H
5+
#define PRODUCER_H
6+
7+
#include <omnetpp.h>
8+
9+
using namespace omnetpp;
10+
11+
class Producer : public cSimpleModule {
12+
private:
13+
cMessage *selfMsg;
14+
int sendCount;
15+
16+
protected:
17+
virtual void initialize() override;
18+
virtual void handleMessage(cMessage *msg) override;
19+
virtual void finish() override;
20+
};
21+
22+
#endif

0 commit comments

Comments
 (0)