当前位置:网站首页>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
边栏推荐
- Introduction notes to PHP zero Foundation (13): array related functions
- ES常用查询、排序、聚合语句
- There is a problem with the light switch from 1 to 100
- 299. Number guessing game
- 安装及管理程序
- ESP32_ Arduino
- Nacos detailed explanation, something
- JIRA screenshot
- Hypermotion cloud migration completes Alibaba cloud proprietary cloud product ecological integration certification
- 深度学习100例 | 第41天-卷积神经网络(CNN):UrbanSound8K音频分类(语音识别)
猜你喜欢

JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory

捡起MATLAB的第(8)天

Cartoon: what are IAAs, PAAS, SaaS?

homwbrew安装、常用命令以及安装路径

Disk management and file system

You need to know about cloud disaster recovery

Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?

OMNeT学习之新建工程

VMware Workstation cannot connect to the virtual machine. The system cannot find the specified file

Install MySQL on MAC
随机推荐
Solution to the fourth "intelligence Cup" National College Students' IT skills competition (group B of the final)
最詳細的背包問題!!!
MySQL的btree索引和hash索引区别
Real time operation of vim editor
LVM and disk quota
捡起MATLAB的第(9)天
Vim使用Vundle安装代码补全插件(YouCompleteMe)
Phpstudy V8, a commonly used software for station construction 1 graphic installation tutorial (Windows version) super detailed
OMNeT学习之新建工程
Force buckle - 198 raid homes and plunder houses
JSP learning 1
05 Lua 控制结构
Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
Government cloud migration practice: Beiming digital division used hypermotion cloud migration products to implement the cloud migration project for a government unit, and completed the migration of n
Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
Day (2) of picking up matlab
Jour (9) de ramassage de MATLAB
阿里研发三面,面试官一套组合拳让我当场懵逼
Detailed explanation of gzip and gunzip decompression parameters
299. 猜数字游戏