当前位置:网站首页>New project of OMNeT learning
New project of OMNeT learning
2022-04-23 16:34:00 【RongLin02】
OMNeT New projects for learning
Preface
I learned that before OMNeT Install and run the official example code , This article records ,OMNeT How to create a new project .
I am a beginner , If there are mistakes, please criticize and correct them !
This article is original. , It's not easy to create , Reprint please indicate !
New project
open OMNeT Installation root path of , open mingwenv.cmd
, Input omnetpp
, open omnet ide.
top left corner File
– New
– OMNeT++ Project...
, Then enter a project name , then Next
, And then choose – Empty project with 'src' and 'simulations' folder
– Finish
.
The file directory is as follows ,
newly build cc file
Let's start by creating a new cc file ,src
– New
– Source File
Then input... In the pop-up interface test.cc
Create a new one cc File to realize the functions of simple modules
Then we enter the following code :
/*
* test.cc
*
* Created on: 2022 year 4 month 21 Japan
* Author: Ronglin
*/
#include <string.h> // String function
// These two lines of code are fixed
#include <omnetpp.h> // Import necessary header files
using namespace omnetpp; // Use command space omnetpp
/**
* Create a test class , Such inheritance cSimpleModule
* In the network , Our new building tic and toc Modules are all Test1 object from omnet++ Created at the beginning of the simulation
* And we're going to rewrite the virtual function initialize() and handleMessage(cMessage *msg) Method
* To implement our custom functions
*/
class Test1 : public cSimpleModule
{
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
// To put Test1 Class is registered in the project
Define_Module(Test1);
/**
* Rewrite the initialization function
* The initialization function is mainly to realize the logical functions to be completed when a module is just created
* In this function , The logical functions realized are
* If the name of this module is "tic" Then create a Message And pass out Send by mouth
*/
void Test1::initialize()
{
if (strcmp("tic", getName()) == 0) {
cMessage *msg = new cMessage("tictocMsg");
send(msg, "out");
}
}
/**
* This method is mainly used when receiving a message
* The logical functions that this module should perform
* In this function , The logical functions realized are
* After receiving the message , Pass the message through out Send it out through the mouth
*/
void Test1::handleMessage(cMessage *msg)
{
send(msg, "out");
}
Give a brief explanation , You can also check against the notes by , First define a class , Then this class should inherit from cSimpleModule
Class and then override the function initialize()
and handleMessage(cMessage *msg)
, At the same time, pay attention to register the class to omnet in .
After you've written build Again , menu bar – Projec
– Build Project
You can complete without reporting an error .
There is no note here for the convenience of copying
#include <omnetpp.h>
using namespace omnetpp;
class Test1 : public cSimpleModule
{
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Test1);
void Test1::initialize()
{
}
void Test1::handleMessage(cMessage *msg)
{
}
The configuration file
Then there is the modification of the configuration file , It's mainly two files , One is omnetpp.ini
, The other one is ned file , All in simulations
Under the folder .
omnetpp.ini
There are few changes in this file , Just enter the network (Network) Name is enough , My name is test_network
package.ned
It opens at simulations
Under folder package.ned
file , Next , Let's create a network .
GUI
First of all, provide GUI Create network in mode
It opens at package.ned
, On the right side Type
Choose the third Network
, Click on it. , Then move the mouse to the left , Click again , You can create a network .
Right click the newly created network , first Properties...
, Here you can set the name of this network , Icon , Location, etc , We just need to change the name , The effect is as shown in the picture , This name should correspond to omnetpp.ini
Network name in .
Then you have to create a model , Click on the following Source
, Then enter the code , The door structure used to define the model
simple Test1
{
gates:
input in;
output out;
}
Then click back Design
, Mouse click Test1
, Drag to the gray box in the network , Because you need two , We drag twice .
then , Check the inside of the gray box Test1
, Right click , first Properties...
, Just change Name, I have one here called tic
, One is called toc
.
Then establish a connection , On the right side palette
– Connection
, And then click tic
Click again toc
, And then choose tic.out-->toc.in
, Established a path from tic
To toc
The connection route , After the connection is established , Because you also need to set the delay , Select line , Right click ,Properties...
– Type
choice DelayChannel
– OK
Pictured .
Then set the delay time , Select line , Right click – Parameters...
, And then click Value
, Input 100ms
then ok.
the reason being that tic and toc Two way communication , We need to connect twice , Empathy , from toc
Click again tic
Establish a two-way connection , Then set the delay , Complete the following figure :
thus , A simple project is created .
Then click... On the toolbar Run
Then a new interface pops up , Click again Run
You can see the delivery of the message
Source
sometimes GUI Although intuitive, modifying properties is cumbersome , Using code directly is simple , Attached directly here is tictoc1
Of ned Code
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
simple Txc1
{
gates:
input in;
output out;
}
//
// Two instances (tic and toc) of Txc1 connected both ways.
// Tic and toc will pass messages to one another.
//
network Tictoc1
{
@display("bgb=641,262");
submodules:
tic: Txc1 {
@display("p=98,146");
}
toc: Txc1 {
@display("p=381,61");
}
connections:
tic.out --> { delay = 100ms; } --> toc.in;
tic.in <-- { delay = 100ms; } <-- toc.out;
}
simple Test1
{
parameters: // Define the parameters of the module
gates: // Define the input and output ports of the module
}
summary
OMNeT Very powerful , But the disadvantage is that there is too little information available on the Internet , I can only grope for myself step by step .
版权声明
本文为[RongLin02]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231627351322.html
边栏推荐
- ESXi封装网卡驱动
- Differences between MySQL BTREE index and hash index
- Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100
- 关于 background-image 渐变gradient()那些事!
- Force buckle - 198 raid homes and plunder houses
- Day (4) of picking up matlab
- JSP learning 2
- Day 9 static abstract class interface
- G008-HWY-CC-ESTOR-04 华为 Dorado V6 存储仿真器配置
- Using JSON server to create server requests locally
猜你喜欢
Hyperbdr cloud disaster recovery v3 Version 2.1 release supports more cloud platforms and adds monitoring and alarm functions
Day 9 static abstract class interface
建站常用软件PhpStudy V8.1图文安装教程(Windows版)超详细
各大框架都在使用的Unsafe类,到底有多神奇?
Solution of garbled code on idea console
Gartner 發布新興技術研究:深入洞悉元宇宙
【Pygame小游戏】10年前风靡全球的手游《愤怒的小鸟》,是如何霸榜的?经典回归......
Gartner announces emerging technology research: insight into the meta universe
Best practice of cloud migration in education industry: Haiyun Jiexun uses hypermotion cloud migration products to implement progressive migration for a university in Beijing, with a success rate of 1
面试题 17.10. 主要元素
随机推荐
七朋元视界可信元宇宙社交体系满足多元化的消费以及社交需求
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
linux上启动oracle服务
Phpstudy V8, a commonly used software for station construction 1 graphic installation tutorial (Windows version) super detailed
欣旺达:HEV和BEV超快充拳头产品大规模出货
Gartner predicts that the scale of cloud migration will increase significantly; What are the advantages of cloud migration?
On the security of key passing and digital signature
How to upgrade openstack across versions
logback的配置文件加载顺序
力扣-198.打家劫舍
撿起MATLAB的第(9)天
Grbl learning (I)
Esxi encapsulated network card driver
JSP learning 3
Day (5) of picking up matlab
Detailed explanation of gzip and gunzip decompression parameters
下载并安装MongoDB
What is the experience of using prophet, an open source research tool?
Solution to the fourth "intelligence Cup" National College Students' IT skills competition (group B of the final)
MySQL personal learning summary