Download - Gioi Thieu Ve Omnet++
-
7/31/2019 Gioi Thieu Ve Omnet++
1/82
OMNet++
Trang 1
1. GII THIU1.1.OMNeT++lg?OMNeT++lvitttcacmtObjectiveModularNetworkTestbedinC++.
OMNeT++lmtngdngcungcpchongisdngmitrngtinhnhmphnghotngcamng.Mcch chnh cangdng lmphnghotngmngthng tin,tuynhindotnhphcpvlinhhotcan,OMNeT++cncsdngtrongnhiulnhvckhcnhmphngcchthngthngtinphctp,ccmngkiuhngi(queueingnetworks)haycckintrcphncng...
OMNeT++ cung cp sn cc thnhphn tng ng vi ccm hnh thc t.Ccthnhphnny(cncgilccmodule)clptrnhtheongnngC++,sauc tphp li thnhnhng thnhphnhaynhngmhnh lnhnbngmtngnngbccao(NED).OMNeT++htrgiaodinho,tngngviccm
hnh cu trc ca n ng thiphn nhn mphng (simulation kernel) v ccmodulecaOMNeT++cngrtddngnhngvotrongccngdngkhc.
1.2.CcthnhphnchnhcaOMNeT++ Thvinphnnhnmphng(simulationkernel)
Trnhbindchchongnngmthnhtrng(topologydescriptionlanguage)-NED(nedc)
Trnhbintpho(graphicalnetworkeditor)choccfileNED(GNED)
Giao
din
ho
thc
hin
m
phng,
cc
lin
kt
bn
trong
cc
file
thc
hinmphng(Tkenv)
Giaodindnglnhthchinmphng(Cmdenv)
Cngc(giaodinho)vthktquvectorura(Plove)
Cngc(giaodinho)mtktquvhngura(Scalars)
Cngctiliuhoccmhnh
Cctinchkhc
Cctiliuhngdn,ccvdmphng...
1.3.ngdngOMNeT++lmtcngcmphngcchotngmngbngccmodulecthitkhngi tng.OMNeT++ thngc sdng trongccngdngchyunh:
Mhnhhotngcaccmngthngtin
-
7/31/2019 Gioi Thieu Ve Omnet++
2/82
OMNet++
Trang 2
Mhnhgiaothc
Mhnhhoccmngkiuhngi
Mhnhhocch thngabvix l(multiprocesser)hoccchthngphncngtheomhnhphntnkhc(distributedhardwaresystems)
nhgikintrcphncng
nhgihiuquhotngcacchthngphctp...
1.4.MhnhtrongOMNeT++MtmhnhtrongOMNeT++baogmccmodulelngnhauccutrcphncp.sucacaccmodulelngnhaulkhnggiihn,iunychophpngisdngcthbiudincccu trclogiccacch thngtrong thc tbngcccutrcmhnh.Ccmoduletraoithngtinvinhauthngquavicgiccmessage(message).Ccmessagenycthccutrcphctptu.Ccmodulecthgiccmessagenytheohaicch,mtlgitrctiptiachnhn,hailgiitheo
mtngdncnhsn,thngquacccngvccktni.
Ccmodulecthcccthamscaringn.Ccthamsnycthcsdngchnhsaccthuctnhcamodulevbiudinchotopologycamhnh.
Cc modulemc thp nht trongcu trcphncpng gicc thuc tnh.Ccmodulenyccoilccmodulengin,vchngclptrnhtrongngnngC++bngcchsdngccthvinmphng.
-
7/31/2019 Gioi Thieu Ve Omnet++
3/82
OMNet++
Trang 3
2. TNG QUAN
2.1.Khi
nim
m
hnh
ho
OMNeT++cungcpchongi sdngnhngcngchiuqum tcu trccacchthngthct.
Ccmodulelngnhauccutrcphncp
Ccmodulelccitngcthcacckiumodule
Ccmoduletraoithngtinbngccmessagequaccknh
Ccthamscamodulelinhhot
Ngnngmttopology
2.1.1.CutrcphncpcaccmoduleMtmhnhtrongOMNeT++chaccmodulelngnhauccutrcphncp,traoithngtinvinhaubngcchgiccmessage.Mimhnhnythngbiudinchomth thngmng.Modulemccaonht trongcu trcphncpcgi lmoduleh thng.Modulenyc thchaccmodulecon,ccmoduleconcngcthchaccmoduleconcaringn.suphncpiviccmodulelkhnggiihn,iunychophpngisdngcthddngbiudinmtcutrclogiccamththngtrongthctbngcutrcphncpcaOMNeT++.
CutrccamhnhcthcmtbngngnngNEDcaOMNeT++
module
h
thng
module
n
gin
modulekthp
HnhI-2.1-CcmodulenginvkthpCc module c th cha nhiu module con v c gi l module kt hp. Ccmodulenginlccmoduleccpthpnhttrongcutrcphncp.Ccmodulenginchaccthuttoncamhnh.NgisdngtrinkhaiccmodulenginbngngnngC++,sdngccthvinmphngcaOMNeT++.
2.1.2.KiumoduleTtcccmoduled lnginhayphc tpu lcci tngc thcacckiumodule.Trong khim t ccm hnh, ngi sdng nh ngha ra cc kiu
-
7/31/2019 Gioi Thieu Ve Omnet++
4/82
OMNet++
Trang 4
module;cci tngc thcacckiumodulenycsdngnhcc thnhphn ca cc kiumodulephc tp hn.Cui cng, ngi s dng tomodule hthngnhmtitngcthcakiumodulecnhnghatrc,ttcccmodulecamngulmodulecon(hoclconcamodulecon)camodulehthng.
Khimtkiumodulecsdngnhmtkhidngsn(buildingblock),skhngthphnbit lmtmodulenginhayphc tp.iunychophpngisdngc th tchccmodulengin ra thnhnhiumodulengincnhngtrongmtmodulekthp,vngclicthtphpccchcnngcamtmodulekthp trongmtmodulenginmkhngnhhnggncckiumodulecngisdngnhngha.
Kiumodulecthclutrtrongmtfileringr.iunychophpngisdngcthnhmcckiumodulelivtoramtthvinthnhphn
2.1.3.Message,cng,linktCcmoduletraoithngtinbngvicgiccmessage.Trongthct,messagecdng khung (frame) hoc l cc gi tin (packet) c truyn i trong mng. Ccmessage c th c cu trcphc tp tu . Cc module n gin c th gi ccmessageimtcchtrctipnvtrnhnhocgiitheomtngdnnhsnthngquacccngvcclinkt.
Thigianmphngaphng (local simulation time)camtmodule tng lnkhimodulenhncmtmessage.Messagec thn tmtmodulekhchocn t cngmtmodule (message ca chnhbn thnmodule - self-message cdngthchinbnhthi).
Cng(gate)lccgiaotipvoracamodule.Messagecgiiquacccngravcnhnvothngquacccngvo.
Miktni (connection)haycngi l linkt (link)c tobn trongmtmc
ntrongcutrcphncpcaccmodule:bntrongmtmodulekthp,mtktnic thc toragiacccngtngngcahaimodulecon,hocgiacngcamoduleconvicngcamodulekthp.
modulecha modulecha
S1 S2 S1 S2
moduleconktnivinhau moduleconktnivimodulecha
HnhI-2.2-CcktniTngngvicu trcphncpcamt m hnh,ccmessage thngdichuynquamtlotccktniviimbtuvktthclccmodulengin.Tpccktniitmtmodulenginvnmtmodulengincgilroute.Ccmodulekthphotnggingnhcccardboardboxtrongmhnh,trongsuttrong vic chuyn tip ccmessage gia cc thnhphnbn trong v th giibnngoi.
-
7/31/2019 Gioi Thieu Ve Omnet++
5/82
OMNet++
Trang 5
2.1.4.MhnhtruyngitinMtktnicthcbathamsctrng.Nhngthamsnyrtthuntinchoccmhnhmphngmngthngtinnhngkhnghudnglmchocckiumhnhkhc.Bathamsnybaogm:
trngtruyn(propagationdelay) tnhbngs-giy.
Tslibit,ctnhbngsli/bit.
Tsdliu,ctnhbngsbit/s.
Cc thamsny ltuchn.Gi trcacc thamsny lkhcnhau trn tngktni,ph thucvokiuca linkt (haycngi lkiucaknh truyn -channeltype).
trngtruynltngthigianncamessagebtrikhitruynquaknh.
Tslibitnhhngnqutrnhtruynmessagequaknh.Tsnylxcsutccbitbtruynsai.Doxcsutmtmessagedinbittruynichnhxcl:
P(messagegiicnhnchnhxc)=(1-ber)ntrongberltslibitvnlsbitcamessage.
Ccmessage truyniu cmt c li, cny sc thit lpkhivic truynmessagecli.
T s d liu c tnh theo n vbit/s, v n c s dng tnh thi gian truyn mtgi tin.Khi tsny cs dng,qu trnh gi messagei trong mhnhstngngvivictruynbitutinvmessagectnhlnnisaukhi
bnnhnnhncbitcuicng.
A B
Messagegii
truynbtr
trngtruyn
tA tB
Messagenhnc
HnhI-2.3-Truynmessage
-
7/31/2019 Gioi Thieu Ve Omnet++
6/82
-
7/31/2019 Gioi Thieu Ve Omnet++
7/82
OMNet++
Trang7
2.3.SdngOMNeT++2.3.1.XydngvchythccmhnhmphngMtmhnhOMNeT++baogmnhngphnsau:
Ngnngmttopology-NED(filecphnmrng.ned):mtcutrc
camoduleviccthams,cccng...Ccfile.nedcthcvitbngbtkbsonthohocsdngchngtrnhGNEDctrongOMNeT++.
nhnghacutrccaccmessage(ccfilecphnmrng.msg):Ngisdngcthnhnghartnhiukiumesssagevthmcctrngdliuchochng.OMNeT++sdchnhngnhnghanysangcclpC++y.
Mnguncaccmodulengin.y lcc fileC++viphnm rngl.hhoc.cc.
Hthngmphngcungcpchotaccthnhphnsau:
Phnnhnmphng.Phnnychacodequn lqutrnhmphngvccthvinlpmphng.NcvitbngC++,cbindch vc
tcngdngviccfilethvin(ccfilecphnmrngl.ahoc.lib).
Giaodinngisdng.Giaodinnycsdngkhithchinqutrnhmphng, to s d dng cho qu trnh sa li,biu din (demonstration)hockhithchinmphngtheotngkhi(batchexecutionofsimulations).Cmtvikiugiaodin trongOMNeT++, ttcucvitbngC++,cbindchvtcngnhautrongccthvin(ccfilecphnmrngl.ahoc.lib).
ThchinmphngvphntchktquCcchngtrnhthchinmphng(thesimulationexecutable)lccchngtrnhclp,tclncthchytrnccmykhckhngcitOMNeT++hayccfile
mhnhtngng.Khichngtrnhkhing,nbtucfilecuhnh(thngthng l file omnetpp.ini). Fileny cha cc thit lp iu khin qu trnhm
phng thchin,ccbinchocc thamscamhnh...Filecuhnhcngc thc s dng iu khin nhiu qu trnhmphng, trong trng hp n ginnht lccqu trnhmphngnysc thchin ln ltbimtchng trnhmphng(simulationprogram).
uracaqutrnhmphnglccfiledliu.Ccfilenycthlccfilevector,ccfilevhnghocccfilecangisdng.OMNeT++cungcpmtcngchoPlovexemvvranidungcaccfilevector.Tuynhinchngtacngnn hiu rng kh m c th x l y cc file kt qu m ch dng ringOMNeT++;ccfilenyulccfilecnhdngcthccbiccgi
x l tonhccaccchng trnhnhMatlabhayOctave,hocc thcavobng tnhcaccchng trnhnhOpenOfficeCalc, Gnumerichay MicrosoftExcel.Tt cccchng trnhnyu cchcnng chuyndng trongvicphntchsho,vbiudin(visualization)vtquakhnngcaOMNeT++.
CcfilevhngcngcthcbiudinbngcngcScalar.Ncthvcccbiu,cc thdavo tphpcc to (x,y)vc thxutd liuvoclipboardc thsdng trongccchng trnhkhcnhmanhngphn tchchitithn.
-
7/31/2019 Gioi Thieu Ve Omnet++
8/82
OMNet++
Trang8
GiaodinngisdngMcchchnhcagiaodinngisdng lchenhngphnphc tpbn trongcu trc ca ccm hnh i vi ngi s dng, d dng iu khin qu trnhm
phng,vchophpngisdngckhnng thayiccbinhaycci tngbn trongcamhnh.iuny l rtquan trngiviphapht trinv sa litrongdn.Giaodinhocngcthcsdngtrnhdinhotngcamhnh.
Cngmtmhnhngisdngc th trnnhiugiaodinkhcnhaumkhngcnphithayigtrongccfilemhnh.Ngisdngcthkimthvsalirtddngquagiaodinho,cuicngcthchyndatrnmtgiaodinnginvnhanhchngchtrthchintheokhi(batchexecution).
CcthvinthnhphnCckiumodulec thclutinhngvtrc lpvichmchngthcscsdng.cimnycungcpchongisdngkhnhmcckiumodulelivinhauvtoraccthvinthnhphn.
CcchngtrnhmphngclpCcchngtrnhthchinqutrnhmphngcthclunhiuln,khngphthucvoccmhnh,sdngcngmtthitlpchoccmodulengin.Ngisdngcthchratrongfilecuhnhmhnhnoscchy.iunytokhnngchongisdngcthxydngnhngchngtrnh thchinlnbaogmnhiuqutrnhmphng,vphnphinnhmtcngcmphngclp.Khnnglinhhotcangnngmttopologycnghtrchohngtipcnny.
2.3.2.HthngfileSaukhicitOMNet++,thmcomnetpptrnhthngmycabnnnchaccthmccondiy.
Hthngmphng:
omnetpp/ thmcgccaOMNeT++bin/ cccngctrongOMNeT++(GNED,nedtool...)include/ ccfileheaderchomhnhmphnglib/ ccfilethvin
bitmaps/ ccbiutnghodoc/ ccfilehngdn,readme...
manual/ filehngdndngHTMLtictoc-tutorial/ giithiusdngOMNeT++api/ APIthamchiudngHTMLnedxml-api/ APIthamchiuchothvinNEDXMLsrc/ mnguncatiliu
src/ mnguncaOMNeT++nedc/ nedtool,trnhbindchmessagesim/ phnnhnmphng
parsim/ ccfilednhchovicthchinphntnnetbuilder/ ccfilednhchoviccngccfileNED
envir/ mngunchogiaodinngisdngcmdenv/ giaodinngidngdnglnh
-
7/31/2019 Gioi Thieu Ve Omnet++
9/82
OMNet++
Trang9
tkenv/ giaodinngisdngdatrnTcl/tkgned/ cngcsonthofileNED
plove/ cngcvvphntchuradngvectorscalars/ cngcvvphntchuradngvhngnedxml/ thvinNEDXMLutils/ cctinchkhc...
test/ bkimthlicore/ bkimthlichothvinmphngdistrib/ bkimthli...
Ccqutrnhmphngmucchatrongthmcsamplessamples/ thmcchaccmhnhmphngmu
aloha/ mhnhcagiaothcAlohacqn/ ClosedQueueNetwork...
ThmccontribchaccchngtrnhcthkthpviOMNeT++contrib/
octave/ scriptcaOctavedngxlktqu
emacs/ bnhducphpNEDchoEmacsNgoirabncngcthtmthyccthmckhcnhmsvc/,chaccthnhphntchhpchoMicrosoftVisualC++...
-
7/31/2019 Gioi Thieu Ve Omnet++
10/82
-
7/31/2019 Gioi Thieu Ve Omnet++
11/82
-
7/31/2019 Gioi Thieu Ve Omnet++
12/82
OMNet++
Trang12
error1e-8
datarate128000//bit/sec
endchannel
3.4.KhaiboccmodulenginCcmodule ngin l cc khi chng trnh cxy dng sn cho ccmodulekhc(cthlccmodulekthp).Ccmoduleckhaibobngtnvtheoquyctncaccmodulenycttnbtubngchciinhoa.
Ccmodulenginckhaibothngquacccngvccthams.
Cphp:
simpleSimpleModuleName
parameters:
//...
gates:
//...
endsimple
3.4.1.CcthamscamodulenginCc thams lccbinph thucvo tngmhnh.Tham scaccmodulengincsdngbicchm(haycncgilccthuttoncamodule)khai
botrongchnhmodule.Theoquycccthamsscttnbtubngchcithng.
Cc
tham
s
c
khai
bo
bng
cch
lit
k
tn
sau
t
kho
parameters.
Kiu
ca
ccthamscthlkius(numeric),hngs(numericconsthayvitgnlconst),gitrlogic(bool),kiuchui(string)hocxml.Khithamskhngkhaiborkiuthmcnhkiucathamslnumeric.
Vd:
simpleTrafficGen
parameters:
interarrivalTime,
numOfMessages:const,
address:string;
gates://...
endsimple
CcthamscthcgngitrtNED(khiccmodulecsdngnhcckhidngsncamtkhikthplnhn)hoctfilecuhnhomnetpp.ini.
Thamsngunhinvhngs
-
7/31/2019 Gioi Thieu Ve Omnet++
13/82
OMNet++
Trang13
Cc thamsckiu sc thct trvmtgi trngunhin theodngphnphiu(uniformlydistributions)hocccdngphnphikhc
Trongas trnghp,cc thams thngchnhngi trngunhinkhibtukhign,saugitrnycginguyn.Khiccthamsnyphickhai
bolhngs-const.Khaibomtthamslconstthgitrcathamsscxcnhmtlnduynhtkhibtuthchinmphngvsaugitrsccoi lhng s. (ChOMNeT++khuynkhchvickhaibomi thams lconsttrnhngtrnghpbnmunsdngchcnngtosngunhin).
ThamsXMLikhiccmodulecnuvolnhngthngtinphctphnkhnngmtcaccthams,khibncthsdngmtfilecuhnhmrng.OMNeT++cthcvxlccfilenythngquamtthamschatncafile.
Tccphinbn3.0trln,XMLccoilmtdngchunchoccfilecuhnhvOMNeT++cngtchhpsncccngcchophpngisdngcthlmviccviccfileXML.OMNeT++chabphn tchcphpXML(XMLparser),ckhnngcccfileDTD,sdngbnhmnhccfile(trongtrnghpmtfileXMLcthamchiutinhiumodulethnscngchphiloadmtln),cung cp cho ngi s dng kh nng chn lc ccphn trong ti liu thng quaXPath,thhinnidungcafileXMLthngquaDOM.
3.4.2.CccngcamodulenginCnglccimktnicamodule.imbtuvktthcmtktnigiahaimodulechnhlcccng.OMNeT++htrkiuktnimtchiu(ncng)dochailoicnglcngvovcngra.Ccmessagecgiitcngravcnhnvo t cng vo.Theoquyc,cc cng ct tnbt ubng ch cithng.
ychngtackhinimvccvectorcngtrongmt vectorcnglmttphpbaogmnhiucngn.
Cngckhaibobngcchkhaibo tn sau tkhogates.Cpdu [] thhinmtvectorcng.Ccthnhphncamtvectorcngcnhsbtut0.
Vd:
simpleNetworkInterface
parameters://...
gates:
in:fromPort,fromHigherLayer;
out:
toPort,
toHigherLayer;endsimple
simpleRoutingUnit
parameters://...
gates:
in:output[];
-
7/31/2019 Gioi Thieu Ve Omnet++
14/82
OMNet++
Trang14
out:input[];
endsimple
Kchthccamtvectorcngcthcxcnhsaudomiitngcthcamtmhnhcthcccvectorcngckchthckhcnhau.
3.5.KhaibomodulekthpModulekt hp l ccmodule c th chamthocnhiu ccmodule con.Btkkiumoduleno(nginhaykthp)ucthcdngnhlmtmodulecon.Cng ging nh cc module n gin, cc module kt hp cng c cc cng, ccthamsvchngcthcsdngbtkchnomccmodulengincthcsdng.
Hnh tnghochng tac th tngtngccmodulekthpgingnhcchpbacngmchng tac thgiuphnmhnhmphngvcccu trcphc tpbntrongn.Khngccchnhvitchcc(activebehaviour)nolinquannccmodule kt hp - chng ch n gin l mt nhm ccmodule kt hp trongmtthnhphnlnhncthcsdngnhmtmhnhhocnhmtkhidngsnchoccmodulekthpkhc.
Theoquyc, tncaccmodule (baogmckiumodulekthp)ucbtubngchhoa.
Ccmoduleconcthsdngccthamscamodulecha.Ccmoduleconnycthktnivinhauhoc/vktnivimodulekthpchachng.
Vickhaiboccmodulekthpcngtngtnhkhaiboccmodulengin.Phn khaibo cngbao gm cc t khoparameters v gates, ngoi ra n cn sdngthmhaitkholsubmodulesvconnections.
Cphp:
moduleTn_module
parameters:
//...
gates:
//...
submodules:
//...
connections:
//...
endmodule
Chlttccckhaibo trn(parameters,gates,submodules,connections)chltuchn.
-
7/31/2019 Gioi Thieu Ve Omnet++
15/82
OMNet++
Trang15
3.5.1.CcthamsvcngcamodulekthpCcthamsvcngcamodulekthpcngckhaibovhotngtngtnhccthamsvcngcaccmodulengin.
Ccthamscamodulekthpcthcsdngbiccmoduleconvthngcdngkhitogitrchoccthamscaccmodulecon.
Ccthamscngcthcsdngxcnhcutrcbntrongcaccmodulekthp:sccmodulecon,kchthccaccvectorcngmtkhcccthamsnycngcthcsdngxcnhccktnibntrongmodulekthp.
Ccthamsnhhngncutrcbntrongcamodulennckhaibolconstgitrcathamskhngthayitheocclntruynhp.Trilinuccthamsckhaibo lccgi trngunhin,ngisdngc thscccgi trkhcnhaumilnthamsctruynhptrongqutrnhxlcamodulekthp.
Vd:
moduleRouter
parameters:
packetsPerSecond:numeric,
bufferSize:numeric,
numOfPorts:const;
gates:
in:inputPort[];
out:outputPort[];
submodules://...
connections://...
endmodule
3.5.2.CcmoduleconCcmoduleconckhaibo sau tkhosubmodules.Theoquycccmoduleconcttnbtuvichcithng.
Ccmoduleconcthlmtmodulenginhocmtmodulekthp.TrnhbindchNEDphibitckiucamoduledoccmoduleconphickhaibosmhnhoccimporttccfileNEDkhc.
Ngi s dng cng c kh nng to ra cc vectormodule con v kch thc cavectornycthnhnvotgitrcamtthams.Khikhaiboccmodulecon,
bncnphigngitrchoccthamscamodulevnukiumoduletngngcsdngccvectorcngthbnphixcnhchonmtkchthccth.
Vd:
moduleTn_Module_kt_hp
//...
submodules:
-
7/31/2019 Gioi Thieu Ve Omnet++
16/82
OMNet++
Trang16
tn_module_con_1:Kiu_Module_1
parameters:
//...
gatesizes:
//...
tn_module_con_2:Kiu_Module_2
parameters:
//...
gatesizes:
//...
endmodule
Vectormodule
Vectormodulelmttphp(mtmng)ccmodulecon.Kchthccavectorcthcbiudinbngmtbiuthcttrongcpdungocvung[].Biuthcnycththamchiunccthamscamodule.Gitr0chosccmodulecngcchpnhn.
Vd:
moduleCompoundModule
parameters:
size:const;
submodules:
submod1:Node[3]
//...
submod2:Node[size]
//...
submod3:Node[2*size+1]
//...
endmodule
3.5.3.ThamstnkiumoduleconVic
s
dng
tn
ca
cc
kiu
module
nh
cc
tham
s
to
iu
kin
d
dng
cho
sdngccmodulecon. Ly vd, cho rngmcch ca qu trnhmphng l sosnh skhcnhaugiacc thut ton tmng.Gi sbn lp trnhcc thutton tm ng cn thit nh cc module n gin DistVecRoutingNode,AntNetRouting1Node, AntNetRouting2Node, ... Bn cng to ra mt topologymngnhmtmodulekthpgilRountingTestNetworkphcvchovicnhgihotngcacc thut ton.Hin tiRountingTestNetworkangsdng thuttonDistVecRoutingNode(ttcccmoduleconuckiuny)vbnmunc
-
7/31/2019 Gioi Thieu Ve Omnet++
17/82
OMNet++
Trang17
thchuyniqualimtcchddnggiaccthuttontinlichovicnhgi.
thc hin iu ny ta c th s dng thm mtbin l routingNodeType chomoduleRoutingTestNetwork.ngthibncngkhaibochoNEDccmoduleconcaRoutingTestNetworkkhngckiucnh,mkiucaccmodulenyclgi tr cabin routingNodeType.Khi mngmphng cabn c th d dngthay i cc thut ton trn thng qua gi tr ca tham s nhDistVectRoutingNode, AntNetRouting1Node hoc AntNetRouting2Node.Trongtrnghpgitrcathamslsai(chatncamtkiukhngtnti)qutrnhmphngsblikhibtuchy-moduletypedefinitionnotfound(khaibokiumodulekhngctmthy).
Bn trongmoduleRoutingTestNetwork, tac thgngitrchocc thamsvtinhnhktniviccmodulechaccthuttontmngtngng.Tuynhintng tnhchnhxc,mbo tnca thamsvcngmbnsdng lchnhxc,
NEDcncsgiptbn.Bnc thkhaibo thmmtmodule(gis tn lRoutingNode)vphimbo chcchn rng ttcccmodule mnh sdngthngqua thams routingNodeTypeuccc thamsvcccnggingnhca
moduleRoutingNode.
Cphp:
moduleRoutingTestNetwork
parameters:
routingNodeType:string;//shouldholdthename
//ofanexistingmoduletype
gates://...
submodules:
node1:routingNodeTypelikeRoutingNode;node2:routingNodeTypelikeRoutingNode;
//...
connectionsnocheck:
node1.out0-->node2.in0;
//...
endmodule
onmnynunhn theogccangnngC++ thRoutingNodengvaitrcamtlpcs,DistVecRoutingNode,AntNetRouting1Nodelcclpktha t
lpRoutingNode.ThamsroutingNodeTypetngngvicontrtrtilpcs.ModuleRoutingNodekhngcncthchintrongC++bikhngcitngcthnocanctora,nchnthuncdngkimtratnhchnhxccafile NED. Mt khc, cc module thc s s c thay th (v d nhDistVecRoutingNode,AntNetRouting1Node,...)skhngcnphikhaibotrongfile
NED.
-
7/31/2019 Gioi Thieu Ve Omnet++
18/82
-
7/31/2019 Gioi Thieu Ve Omnet++
19/82
-
7/31/2019 Gioi Thieu Ve Omnet++
20/82
OMNet++
Trang20
submodules:
node:Node[count]
parameters:
position="middle";
parameters
if
index==0:position="beginning";
parametersifindex==count-1:
position="end";
gatesizes:
in[2],out[2];
gatesizesifindex==0||index==count-1:
in[1],out[1];
connections:
//...
endmodule
Chccgi trmcnhnnckhaibou tinbivNEDsduyt t trnxungdi,nugpiukinngthccgitrtngngscchnvoccgitrmcnh trc.Trongtrnghpkhaibogi trmcnhcuicng,gitrmcnhscthchnvogitrcamttrnghpiukinngtrc.
3.5.7.KtniCcktnich rac thcchcccngcamodulekthpgiao tipvicccngtngngcamodulecon.
Ktnicthctoragiahaimoduleconhocgiamoduleconvimodulecha(modulekthp) trctipchan(trongmtst trnghp,mtktnicngcthc to ragiahaicngcacngmtmodulekthp).iunycngha l
NEDkhngchophpmtktniacp(ktnigiahaimodulexanhautrongcutrcphn cp). Hn ch ny lm tng tnh c lp v kh nng dng li ca mimodule.Ngoira,hngcamodulecngrttrongquantrngkhitoktni.Khngthtomtktnigiahaicngrahocgiahaicngvovinhau.
NEDchhtrkiuktnimt-mtdomtcngringbitcsdngchxuthin mt ln trongmt kt ni. Kiu kt nimt-nhiu v nhiu-mt cng c thctorabngcchsdngccmodulengintrongcclungmessagecnhnihoccghpthm(duplicatemessageormergemessageflows).
Ccktniclitksautkhoconnectionsvcphntchvinhaubngduchmphy.
Vd:
moduleCompoundModule
parameters://...
gates://...
-
7/31/2019 Gioi Thieu Ve Omnet++
21/82
OMNet++
Trang21
submodules://...
connections:
node1.output-->node2.input;
node1.inputnode[1].in++;
node[0].in++node[2].in++;
node[1].in++node[4].in++;
node[1].in++node[4].in++;
node[3].in++node[5].in++;
node[4].in++
-
7/31/2019 Gioi Thieu Ve Omnet++
22/82
OMNet++
Trang22
Cthxuthintrongmtvnglp(toranhiuktni).
Cthliukin.
KtninvknhtruynNubnkhngxcnhmtknhtruyn,thktniskhngctrvkhngcbit
likhitruyn.Bncthxcnhmtknhtruynthngquatn.Vd:
node1.outGate-->Fiber-->node2.inGate;
TrongtrnghpnyfileNEDphickhaiboloiknhtruyntrn.Hocngisdngcngcthxcnhtrctipmtknhtruynquaccthamsctrng.
Vd:
node1.outGate-->error1e-9delay0.001-->node2.inGate;
Khngnhtnhphikhaiboyccthamsvccthamscthckhaibotheobtkthtno.
KtnivnglpNumoduleconhocccvectorcngcsdng,NEDchophpngisdngcthtoranhiuhnmtktnivimtkhaibo.cgilmtaktnihaymtktnivnglp.
fori=0..4do
node1.outGate[i]-->node2[i].inGate
endfor;
Mtaktnithcchtlmttphpccktninckhaibognhnnhculnhvnglpfor...do...endfor.
HnhI-3.1-aktniCcktniciukin
Ngisdngcthsdngtkhoifrngbuciukinkhitoccktni.Vd:
fori=0..ndo
node1.outGate[i]-->node2[i].inGateifi%2==0;
endfor;
Nocheck
-
7/31/2019 Gioi Thieu Ve Omnet++
23/82
OMNet++
Trang23
Mcnh,NEDquynh ttccccnguphicktnidovy trongnhiutrnghpvickimtranyc thgynhiuphinphc.ttbchcnngny
bncthsdngtkhonocheck.
3.6.Khaibomng thc s tomtmhnh mphngchyc thngi sdngphikhaibomng.Vickhaibomngstoramtmhnhmphngnhlmtitngcthcamtkiumodulenhngha trc.Kiumoduley thng lmtmodulekthp, tuynhincngc th toramtmngch lmtmodulenginclp.
CthkhaibonhiumngtrongmthocnhiufileNED.ChngtrnhmphngsdngccfileNEDscthchybtcmtmngno.Nubnmuncthmtmngnocthchinbncthchrtrongfilecuhnh(omnetpp.ini).
Cphpkhaibomngcngtngtnhkhaiboccmodulecon:
networkwirelessLAN:WirelessLAN
parameters:
numUsers=10,
httpTraffic=true,
ftpTraffic=true,
distanceFromHub=truncnormal(100,60);
endnetwork
yWirelessLANltncamtkiumodulekthpnhnghattrc,trongc thchacckiumodulekthpkhcnhWirelessHost,WirelessHub...Mt
cch
t
nhin,
ch
cc
kiu
module
khng
c
cng
mi
c
th
c
dng
trong
cckhaibomng.
3.7.CcbiuthcCcbiu thcc sdng trongNEDcvit theo cphpcaC++.Ccbiuthc dng cc ton t caC++, c th s dng cc tham s theo c hai hnh thctruyn theo tham tr hoc thambin, c thgi cc hmcaC++, nhn ccgi trngunhinhocyucunhptngisdng...
Khimtthamscgntrbngmtbiuthcthgitrbiuthcchctnhmi ln tham s c gi ti (tr khi tham s c khaibo const).iu ny c
ngha lmtmodulen gin s dngmt tham s khng c khaibo const snhncccgi trkhcnhaumi lngi thams trongqu trnhmphng.Cc
biuthckhc(chaccthamsckhaiboconst)schctnhmtln.CcthamsckiuXMLcthcdngtruynhpvoccfileXMLhaymtphnno ca cc file ny.Tham s kiuXML c th c gn gi trbng ton txmldoc().
-
7/31/2019 Gioi Thieu Ve Omnet++
24/82
OMNet++
Trang24
3.7.1.HngsHngshcHng shc thng lcc sdng thpphnhoccc s thpphnviduphyng.
HngchuiktHngchuiktckhaibogiacpdungockp.
Hngthigiansdnghngthigianbnphisdngthmcctkhochnvthigian.
Vd:
...
parameters:
propagationDelay=560ms,//0.560giy
connectionTimeout=6m30s500ms,//390.5giy
recoveryIntvl=0.5h;//30pht
Ccnvthigiancthcsdng:
nv ngha
ns nano giy
us microgiy
ms miligiy
s giy
m pht(60giy)
h gi(3600giy)
d ngy(86400giy)
3.7.2.ThamchiuCcbiuthccthsdngccthamscamodulekthptrctipchanvcaccmodulenginckhaibotrctrongfileNED.
Cphp:submod.paramhocsubmod[index].param.
Chaitkhocthcsdngvitncathams:ancestorvref.
ancestorcnghalnumtmodulekthpkhngchamtthamsno,ththams s c tm kim trong cc module cp cao hn trong cu trcphn cp.ancestorkhngckhuynkhchsdngbivnxmphmtikhinimng
-
7/31/2019 Gioi Thieu Ve Omnet++
25/82
OMNet++
Trang25
githngtin(encapsulation)vcthchckimtratrongthigianchy.Nchnncsdngtrongmtstnhngtrnghpthcscnthit.
reflygitrcathamsbngphngphpthamchiu,cnghalvicthayigitr ca tham s trong thi gian chy s gy nh hng ti tt c ccmodule thamchiu tithamsny.Cnggingnhancestor,refnncsdnghnch.Mttrnghpcthsdngreflkhiphiiuchnhmhnhtrongthigianchytmiukintiu.Ngisdngcthkhaibomtthamsmccaonhtcamhnhvtccmodulekhcthamchiutithamsny.Khibn thayithams ny trong thi gian chy, n s nh hng ti tonbm hnh.Trongmt strnghpkhc,ccthamscthamchiucthcdngnhccbintrngthiiviccmodulebncnh.
3.7.3.CctontCctontchtrtrongNEDcngtngtnhcctonttrongC/C++,tuynhincngcmtskhcbit:
Du^cdngchophptnhlutha(khngphilphpXORccbitnhtrongC).
Du#csdngchophptonlogicXOR(tngtnhdu!=)v##cdngchophptonbitXOR.
Thtutincaccphptonbit(&, |,#)lcaonhtsovicctontquanhkhc.
TtcccbintrongNEDuckiudoubles.ivicctontbit,kiudoublescchuynthnhkiuunsignedlongbnghmchuynicsncaC/C++(typecast), sau khiphp ton c thc hin kt qu s c chuyn i li thnh kiudoubles. Tng t i vi cc ton t logic &&, || v ##, cc ton hng s cchuynsangkiubool(typecast)vsauktqus licivkiudoubles.iviphpchialyphnd(%),tonhngscchuynsangkiulong.
Danhschcctontvthtutin:
Tont ngha
-,!,~ dum,phnh,lyphnbcabit
^ phptonlutha
*,/,% phpnhn,chia,chialyphnd
+,- phpcng,tr
phpdchbit
&,|,# phptonbitand,or,xor
== sosnhbng
!= sosnhkhc
-
7/31/2019 Gioi Thieu Ve Omnet++
26/82
OMNet++
Trang26
>,>=
-
7/31/2019 Gioi Thieu Ve Omnet++
27/82
OMNet++
Trang27
xmldoc() nhn vo tn file.Vd:xmlparam=xmldoc(someconfig.xml);
xmldoc() nhn vo tn file cng thmXPath,biu thc ch ramt element c thc chn trong file XML.Vd:xmlparam=xmldoc("someconfig.xml","/config/profile[@id=2]");
3.7.6.XMLvXPathThamsXPathcatontxmldoc()chramtelementcthtrongfileXML,iunychophpddngninhiufilecuhnhdngXMLnhthnhmtfilelnhn.
NubiuthcXPathphhpvinhiuelementtrongfilethelementutin(thtduyttheochiusu)scchn.
Cphpcabiuthc:
Biuthcchangdntrongccthnhphncphntchbngdu/hoc//.
Ccthnhphncangdncthltnth(tagname)caccelement,du*,. hoc ...Tn th ca cc element v du * c th c thmbiu thcm tthuctnhcaelementtheodng[vtr]hoc[@thuc_tnh=gi tr].VtrcaccelementtrongfileXMLctnhbtut0.
Du/cnghalxtccelementcon;du//sxtnccelementbtkcpnonmdielementhinthi.
Du ., .. v * ln lt i din cho element hin thi, element cha vmtelementvitnbtk.
Vd:
/fooelementgc(rootelement)ctnl
/foo/barelementconutincaelementgc
//barelementutinbtkcpno(duyttheochiusu)
/*/barelementconutincaelementgcctnbtk
/*/*/barelementconutindihaicpcaelementgc
/*/foo[0]elementconutincaelementgc
/*/foo[1]elementconthhaicaelementgc
/*/foo[@color=green]elementconutincthuctnhcolorcgitrbnggreen
//bar[1]mtelementvtrbtknhngphilelementthhai
//*[@color=yellow]btkelementnobtkvtrnocthuctnh"color"cgitrbng"yellow"
//*[@color=yellow]/foo/bar element conu tin ca element conutincamtelementcthuctnhcolorbngyellowvtrbtk.
3.7.7.HmTrongNED,bncthsdngcchmtonhcsau:
-
7/31/2019 Gioi Thieu Ve Omnet++
28/82
OMNet++
Trang28
Rtnhiuhmc trong thvin toncaC (math.h)nh exp(), log(), sin(),cos(),floor(),ceil()...
Cchmtogitrngunhin:uniform,exponential,normal...
3.7.8.GitrngunhinCcthamstrkhickhaibolconst,nukhnggitrcaccthamsthnglccgitrngunhin.Ccgitrnylkhcnhaumilnthamscgin.Cc gi tr ngu nhin c sinh ra nhb to s ngu nhin (RandomNumberGenerator-RNG)caOMNeT++.
Hm Mt
Lutphnphilintc
uniform(a,b,rng=0) lutphnphiutrongkhong[a,b)
exponential(mean,rng=0) lutphnphitheolutsmvigitrtrungbnhmean
normal(mean,stddev,rng=0) lutphnphibnh thng vi gi tr trungbnhmeanvlchchunstddev
truncnormal(mean, stddev,rng=0)
lutphnphibnh thng loib cc s khngm
gamma_d(alpha,beta,rng=0) lutphnphigammavialpha>0vbeta>0
beta(alpha1,alpha2,rng=0) lutphnphibetavialpha1>0valpha2>0
erlang_k(k,mean,rng=0) lutphnphiErlangvik>0phavgi tr trungbnhmean
chi_square(k,rng=0) lutphnphichi_squarevik>0tdo
student_t(i,rng=0) lutphnphistudent_tvii>0tdo
cauchy(a,b,rng=0) lutphnphiCauchyvicc tham sa,b trongb>0
triang(a,b,c,rng=0) lutphnphitamgicviccthamsa0,b>0
pareto_shifted(a,b,c,rng=0) lutphnphiParetotngqutviccthamsa,
-
7/31/2019 Gioi Thieu Ve Omnet++
29/82
OMNet++
Trang29
bvdchc.
Lutphnphirirc
intuniform(a,b,rng=0) lutphnphi u vi cc s nguyn nm trongkhonga..b
bernoulli(p,rng=0) kt qu caphp th Bernoulli vi xc sutp,0
-
7/31/2019 Gioi Thieu Ve Omnet++
30/82
OMNet++
Trang30
mttnkhcvitnmhmcgikhisdng.Trongtrnghphmkhngtrvkiudoublebncngcthlmtngt.
#include
longfactorial(intk)
{
...
}
staticdouble_wrap_factorial(doublek)
{
returnfactorial((int)k);
}
Define_Function2(factorial,_wrap_factorial,1);
-
7/31/2019 Gioi Thieu Ve Omnet++
31/82
OMNet++
Trang31
4. GII THIU GNED
4.1.Giao
din
GiaodincaGNEDhtrhaich:
ho(Graphics):lgiaodinmcnh.
Mngun (NEDSource):chophpngi sdngc th sa limngunmtcchtrctip.
HaikiugiaodinnycthanhCommandBarlkhcnhau.ivichho,thanhCommandBarcdng:
NewNEDfile:tomtfileNEDmi.GNEDchophptonhiufileNEDcngmtlc.
OpenNEDfile:mmtfileNED.
SaveDocument:GhifileNEDhinthi.
-
7/31/2019 Gioi Thieu Ve Omnet++
32/82
OMNet++
Trang32
Addnewcomponent tocurrentNED file:mtdanh sch thxung (dropdownlist) chophp ngi s dngmt trong 5 thnhphn c th thm vo fileNED:Import,Channel,SimpleModule,CompoundModulevNetwork.
Backtopreviousview:quaylichgiaodintrctrongHistory.
Forwardtonextview:chuyntichgiaodintiptheotrongHistory.
Select,move or resize itemsbutton: khi nt nyc kch hot, n chophpngisdngcthchn,dichuynvthayikchthcccitngtrongchho.
Drawsubmodulesandconnection tool:Cngc toccmoduleconvccktni.Kchchutvkor toccmodulecon.Kchchutbn trongmtmodule
conkorsangmodulekhc toktnimtchiugiahaimodule.tomt ktnihaichiutathchinvictoktnimtchiuhailntheochiungcnhau.
Appearance of selected items:Chc nng hot ng khimt (v chmt) itng c chn.N s lm xut hin cc trnh n nh SubmoduleAppearance,Module Appearance hayConnectionAppearance.Cc trnh n ng cnh ny cho
phpbnmtchititchoitngcchn.
Propertiesofselecteditems:thuctnhcaitngcchn.
Snaptogridon/offswitch:bt/ttchbtdnhvoliim.
Fitcompoundmodule toareacontent:nntny s lmchobincamodulechacmrngrachatrnvnbincattcccmodulecon.
Trong
ch
NED
Source,
thanh
Command
Bar
c
dng:
BnntucchcnngtngtnhtrongchGraphic.
Backtopreviousmodule:kchhotmodulechntrc.
Forwardtonextmodule:kchhotmoduletiptheo.
Cut:dichuynvoclipboard.
Copy:saochpvoclipboard.
Paste:dntclipboard.
Undo:hubthaotcvathchin.
Redo:lplithaotcvahub.
FindText:tmkimtrongvnbn.Chcnngnyslmxuthinhpthoi:
-
7/31/2019 Gioi Thieu Ve Omnet++
33/82
OMNet++
Trang33
Hp thoi chophp tmkimvi cc chc nng (b lc): regular expression, casesensitive...
PhnbntricagiaodinlTreeView.TreeViewchophpquanstttcccfilevccmoduleangcm.
HaimcnedfileUntitledcnhdumunhcnh lhaifilenychaSave.
Nubn kchphichutvo mtmcno trongTree View, mt trnhn ngcnhshinra.Trnhnnychaccthao
tccbnmbncththao
tcv
i
itngtngng.
KhibnmisdngGNED,sthngcmtcasnhhinlnmilnbnthchinmtthaotc.Casnygiithchchobncchthchotngcamtschcnngphctp tronggiaodincaGNED.Bncttchcnngnybngcchnhduvohpchnphadicacas.ylmtchcnngrthuchvvykhi
bnttchcnngnyi,munnxuthintrlibnphixofile.gnedrc.
-
7/31/2019 Gioi Thieu Ve Omnet++
34/82
OMNet++
Trang34
4.2.MtsthaotccbnTomtmodulecontrongmodulekthp
Kch thccamodulekthp s tngiuchnhchophhpvimoduleconctora.Nhni trnnubn lmtngisdngmi,scmtcashngdnnhxuthin:
NhnOK,tngtbntothmmtvimodulenhtronghnhv:
-
7/31/2019 Gioi Thieu Ve Omnet++
35/82
OMNet++
Trang35
Tiptheotasdngcngc chnmttrongccmoduleconvactora.Bincamodulecchnchuynthnhmu.
nnt ,bnsthytrnhnngcnhSubmoduleAppearance:
Trnh n ny chophp ngi s dng c th thay i hnh dng camodule contngng. Kchchnchcnng Iconchn mt Iconbiudin cho modulequatrnhduytho.
-
7/31/2019 Gioi Thieu Ve Omnet++
36/82
OMNet++
Trang36
BncthsdngnhngIconcsncaOMNeT++hoccththmccIconcaringmnhbngcchcopyccfilebitmapvothmcbitmapcaOMNeT++.
ChnIconballvikchthctrungbnh(normal).TacngcththayimuscchoccIcon.
Chuyn Iconball tmuxmsangmuxanh:kchvohnhchnhtbncnhColorizeicon,mtbngchnmushinra
-
7/31/2019 Gioi Thieu Ve Omnet++
37/82
OMNet++
Trang37
Saukhichnmuxanh,bygibncthxemlihnhdngcamoduleconmbnvamithayisovihnhchnhtcaccmodulec.
ChuynsangchnhnNEDSource
Bncththymnguncamhnhmbnvato:
Chlivimoduleconthnhtnhngthayivmthnhthccancdinttrongchuii=ball,#0080ff.Bngcchsdngccchcnngcopy,pasteta
-
7/31/2019 Gioi Thieu Ve Omnet++
38/82
OMNet++
Trang38
cththayihnhthcchoccmoduleconcnlimkhngcnphimtrnhnSubmoduleAppearancechotngmoduletngng.
sinhnghn, ta thayi thamsmuscchoccmodulecn li,submod1thnh#ff80ffvsubmod2thnh#ff8000.Ktqucthhinhnhdi:
Nhvy trongGNED,haichgiaodincnhhngqua li lnnhau.Nhngthayitrongchnycngnhhngnchcnli.
Bygichngtassdngccmodulenythnghimchcnngcabtos
ngunhin(RandomNumberGenerator-RNG).Trctin,kchphichutvotngmodulevchnchcnngRenameitnchoccmoduletheothtlnltlrng,checkervcounter.
rngssinhraccsrichuynquachochecker.checkerstnhlitrnmisvchchuynchocounterccschn,ccslsbbi.countersghilislng schn mnhn c trong tngpht,vsny sc truyni choccthnhphnbnngoikhicyucu.
Tasdngcngc toktnitheomhnhmttrn.rngphinivicheckervcheckernivicounter.
-
7/31/2019 Gioi Thieu Ve Omnet++
39/82
OMNet++
Trang39
countercncnhimvnhnvgimessageviccthnhphnbnngoi,dotaphi to thmccktnicn thit.ktnimtmodulevibnngoi,ko rchutttmmoduletibincavngmuxm.ktninylhaichiu, tatinhnhtoktnitheochiungclitbinvotmcamodule.
Bygi tai tnchomodulekthp thnh rnd_evalbngcchkchphi chutvo dng ch Module nm gc trn tri ca vng mu xm, chn chc nng
Rename
trong
trnh
n
ng
cnh
tng
ng.
Save file vi tn Random_Number_Evaluator.ned, chng ta cmt fileNEDhonchnh.
4.3.LmvicvinhiufileNED-Ccchcnngchnhsanngcao
Nhn nt to mt ti liuNED mi. To mt module con mi c tn lconductor.
-
7/31/2019 Gioi Thieu Ve Omnet++
40/82
OMNet++
Trang40
Saukormodulernd_evalcafiletavatotrnvomoduleModulecafilemibaln.
Cc module rnd_eval s ln lt c t tn l rnd_eval, rnd_eval1,rnd_eval2.Sautatoktnihaichiugiamoduleconductorviccmodulernd_evalvathmvo.Moduleconductorsthnhthongyucuccsliucaccmodulernd_evalvccmodulenysgimessagetrli.
-
7/31/2019 Gioi Thieu Ve Omnet++
41/82
OMNet++
Trang41
QuansttrnTreeView,tasthyccktnivactngtora
VfileNEDcngcnhngthayitngng
-
7/31/2019 Gioi Thieu Ve Omnet++
42/82
OMNet++
Trang42
Savefileminyvitnconductor.ned.
thnghimcachng ta thcshotng,chng tacnphikhaiboRnd,
Checker,Counternhccmodulengin.
Bcutin,chngtato3modulengin.nnt ,hocsdngtrnhnng cnh trn Tree View thm vo mt module n gin. Ca s ModulePropertiesxuthin,chntabReneralvgvoNametncamoduleRnd.
ChntabParametersnhnghaccthams(ccthamsnycthscccRNGsdng),bngcchnybncthcuhnhlisauny.
-
7/31/2019 Gioi Thieu Ve Omnet++
43/82
OMNet++
Trang43
Chn tabGates v khaibomt cng, qua cc s ngu nhin sinh ra s ctruyni.Bnc thsdng trngEnd-linecommentvitch thchchochcnngcacng.
BygimoduleRndsnsngvbncthiukhinhotngcamodulenythngquaccfiletngngRnd.ccvRnd.h.
Tng tnh trn, ta tip tckhaiboccmodulengin ckiuCheckervCounter.
Tip theo ta thayikiucamimoduleconbn trongmodule rnd_evalchophhp vi cc kiumodule n ginmim ta va to ra.Kch chutphi vo tnmodulerng,chnProperties...,sauchntrongTypekiuRnd.
-
7/31/2019 Gioi Thieu Ve Omnet++
44/82
OMNet++
Trang44
Thayitngtiviccmodulecnli,sausavefileli.
Bn thy rngccmoduleconrng,checkervcounterccckiumoduletngng.Ngoi ra,nubnkchchutphivo simpleRndvchnShowNEDcode...,bnsthynhngkhaibobnthchintrongcasModulePropertiestrncthhindidngm:
QuaylivifielConductor.ned,filenysdngmodulernd_eval,mtmodulekt hp c nh ngha trong file Random_Number_Evaluator.ned.Do bn
-
7/31/2019 Gioi Thieu Ve Omnet++
45/82
OMNet++
Trang45
phi import file Random_Number_Evaluator.ned c th s dng modulernd_eval.
nnt vchnmcImports
GtnRandom_Number_EvaluatorvotrngName(chkhnggthmphnmrng.ned).Ngoirabncththmvocclichthchhaicttiptheo.
Savefileconductor.ned.
Bnhonthnhmtmhnhmngngin.chycmhnhny,bnphitrinkhaiccmodulengintrongC++vxydngccfile.exe.
-
7/31/2019 Gioi Thieu Ve Omnet++
46/82
OMNet++
Trang46
5. MODULEN GIN
5.1Module
n
gin
trong
OMNeT++
Ta sdngC++xydngccsimplemodule thchincc skin,haynikhcilthchincchotng(behaviour)camhnh.
Cc module do ngi lp trnh xy dng thng l cc lp k tha t lpcSimpleModuletrongthvincaOMNeT++.
Mimodulethngchacchmsau:
voidinitialize()
voidhandleMessage(cMessage*msg)
voidactivity()
voidfinish()
Hmkhitoinitialize()Trongqutrnhkhito,OMNeT++sxydngmng:ntoraccmodulenvccmodulekthp(compoundmodule).Sauktnichng theocckhaibovnhnghatrongfileNED.
HmhandleMessage()andactivity()Cchmnycgikhitrongqutrnhxlskin.Nhvyhuhthotngca h thng c m phng s c lp trnh trong cc hm ny. HmhandleMessage() s c nhn mphng (simulation kernel) gi khimodule nhn
cmtgitin.V thngthng,tachyuxydnghmhandleMessage()thayvhm activity().
Hmfinish()Hm finish()cgikhiqu trnhm phngkt thc thnhcng.Ngoi ra,mtngdngchyucahmnycnlthuthpccthngkvqutrnhmphng.
5.2CcskintrongOMNeT++OMNeT++sdngccmessagebiudinccskin.Miskincbiudin
bimtitngcalpcMessagehoclpconcalpny.
5.3MhnhhohotngtruyngitinTng tnh trnhby trongphn2.1.4, Mtktnic thcba thamsctrng.Nhng thamsny rt thun tinchoccmhnhmphngmng thng tinnhngkhnghudnglmchocckiumhnhkhc.Bathamsnybaogm:
trngtruyn(propagationdelay) tnhbngs-giy.
-
7/31/2019 Gioi Thieu Ve Omnet++
47/82
OMNet++
Trang47
Tslibit,ctnhbngsli/bit.
Tsdliu,ctnhbngsbit/s.
Cc thamsny ltuchn.Gi trcacc thamsny lkhcnhau trn tngktni,ph thucvokiuca linkt (haycngi lkiucaknh truyn -channeltype).
5.4Khaibokiumodulengin5.4.1TngquanMtmodulevitbngC++baogm:
Khaibolpmodule:lpdongilptrnhxydngllpconcalpcSimpleModule.
ngkkiucamodule(moduletyperegistration):Define_Module()hocDefine_Module_Like() macro.
Trinkhaicthlpmodule.
XtVDsau:
//file:swp.cc#include
//moduleclassdeclaration:classSlidingWindowProtocol :publiccSimpleModule{Module_Class_Members(SlidingWindowProtocol, cSimpleModule,0)virtualvoidhandleMessage(cMessage*msg);
};
//moduletyperegistration:Define_Module(SlidingWindowProtocol );
//implementationofthemoduleclass:voidSlidingWindowProtocol::handleMessage( cMessage*msg){...}
ModuletrnckhaibotrongfileNEDnhsau:
//file:swp.ned
-
7/31/2019 Gioi Thieu Ve Omnet++
48/82
OMNet++
Trang48
simpleSlidingWindowProtocol parameters:windowSize:numericconst;
gates:in:fromNetw,
fromHigherLayer;
out:toNetw,toHigherLayer;
endsimple5.4.2ngkkiumoduleTrongVDtrnchaculnh:
Define_Module(SlidingWindowProtocol); DnglnhnyskhinchoOMNeT++bitrngtamundnglpSlidingWindowProtocol didng1modulen.ngthiOMNeT++frameworkstmfileNEDccngtnchakhaibovmoduleny(simpleSlidingWindowProtocol...endsimple)
xcnhcccngvccthamsmmodulenycnc.
5.5XydnghmchoModule5.5.1HmhandleMessage()HmhandleMessage()cgikhimimessagenmodule.Khihmnysxlgitinvtrliktqungaylptc.
Ch rng ccmodule hmhandleMessage()KHNG c t ng gi,mphinhncgitin tmodulekhc.Muntaphi thmccself-message thmkhitoinitialize()thhmhandleMessage()sbtulmvicmkhngcnphinhngitintmodulekhc.
sdnghmhandleMessage()trongmtmodule,taphixcnhkchthc cazerostacksizechomodule.Bilkchthccazerostack skhinOMNeT++
bittamunsdnghmhandleMessage()hayactivity().
MtshmthngdngmtacthsdngtronghmhandleMessage():
Cchmsend():gigitinticcmodulekhc.
HmscheduleAt():nhkmtskin (thng lmodule tgigi tinchochnhn)
HmcancelEvent():hybnhkmtskinnhhmscheduleAt()
Chrngcchmreceive()v wait()khngcsdngtrongvicxydnghmhandleMessage(),mchdngkhitamunxydnghmactivity().
VD1:
-
7/31/2019 Gioi Thieu Ve Omnet++
49/82
OMNet++
Trang49
classFooProtocol:publiccSimpleModule{protected://statevariables//...
virtualvoidprocessMsgFromHigherLayer(cMessage*packet);virtualvoidprocessMsgFromLowerLayer(FooPacket *packet);virtualvoidprocessTimer(cMessage*timer);
public:Module_Class_Members(FooProtocol, cSimpleModule,0);virtualvoidinitialize();virtualvoidhandleMessage(cMessage*msg);
};
//...
voidFooProtocol::handleMessage( cMessage*msg){if(msg->isSelfMessage())processTimer(msg);
elseif(msg->arrivedOn("fromNetw")) processMsgFromLowerLayer(check_and_cast(msg));
elseprocessMsgFromHigherLayer(msg);
}5.5.2Hmactivity()Cchmquantrngmtacthgitronghmnybaogm:
receive()
wait()
send()
scheduleAt()
cancelEvent()
end()
-
7/31/2019 Gioi Thieu Ve Omnet++
50/82
OMNet++
Trang50
5.5.3Hminitialize()vfinish()Hminitialize():khitoccgitrcnthitchoqutrnhmphng
Hmfinish():hmnycsdngghiliccthngs trng thicn thitkhiqutrnhmphngktthc.
5.6Givnhnccmessage5.6.1GiccmessageSaukhitoraccgitin,tacthginthngquamtcngvo/ranhhmsend()vicphpnhsau:
send(cMessage*msg,constchar*gateName,intindex=0);send(cMessage*msg,intgateId);send(cMessage*msg,cGate*gate);
Vd:
send(msg,"outGate");send(msg,"outGates",i);//sendviaoutGates[i]
onmsaustoravgiccgitinsaumi5giy.
intoutGateId=findGate("outGate"); while(true){send(newcMessage("packet"),outGateId);wait(5);}5.6.2BroadcastsKhitamuncngmtgitintinhiuntchngthi,thdngphngphptoranhiubnsaocagitinvgichngi.
Vd:
for(inti=0;idup();send(copy,"out",i);
}deletemsg;
-
7/31/2019 Gioi Thieu Ve Omnet++
51/82
OMNet++
Trang51
5.6.3Gictr(Delayedsending)wait(someDelay);send(msg,"outgate");
Cphpcngtngtnhtrn,chthmthamsthigiantr
sendDelayed(cMessage*msg,doubledelay,constchar*gateName,intindex);sendDelayed(cMessage*msg,doubledelay,intgateId);sendDelayed(cMessage*msg,doubledelay,cGate*gate);
Vd:
sendDelayed(msg, 0.005,"outGate");5.6.4GitrctipmessageSdnghmsendDirect()gitrctipgitintmodulenytimodulekiamkhngcnquantmnthngquacngno.
sendDirect(cMessage*msg,doubledelay,cModule*mod,intgateId)sendDirect(cMessage*msg,doubledelay,cModule*mod,constchar*gateName,intindex=-1)sendDirect(cMessage*msg,doubledelay,cGate*gate)
Vd
cModule*destinationModule=parentModule()->submodule("node2"); doubledelay=truncnormal(0.005,0.0001);sendDirect(newcMessage("packet"),delay,destinationModule, "inputGate");5.6.5GinhkscheduleAt(absoluteTime, msg);scheduleAt(simtime()+delta,msg);
5.7Truynhpcccngvktni5.7.1itngcng(gateobject)Modulecnglmtitngcalp cGate.Hmgate()strv1contrtiitngcGate.Vmuntruycpvotngthnhphncacng,tathchinchnghm
cGate*outgate=gate("out");cGate*outvec5gate=gate("outvec",5);
-
7/31/2019 Gioi Thieu Ve Omnet++
52/82
OMNet++
Trang52
GateIDCcmodulecngclutrtrongmtmng.VitrcacngtrongmngilgateID.xcnhgateID,tadnghmid()hochmfindGate()intid=outgate->id();or:intid1=findGate("out");intid2=findGate("outvect",5);
Nh,cthgivnhngitinthngquathamslgateID.ThngthngthvicsdnggateIDsnhanhhnldngtncng.
5.7.2CcthamsktniCcthngsthngscbncangtruyn:tr,tlbitli,tctruync
biudinthngquaitngchannel.
cChannel*chan=outgate->channel();
cBasicChannel*chan=check_and_cast(outgate->channel()); doubled=chan->delay();doublee=chan->error();doubler=chan->datarate();
5.8TngtomoduleTrongmtstnhhung,tacnphitngtovhyccmodule.Chnghnkhimphngmtmngding,tacntomtmodulemikhingidngtinvovngktnivhymodulenykhingirakhivngktni.
Qutrnhtrngm5bc:
1. Tmloimodule.
2. Tomodule
3. Thitlpccthamsvkchthccng(nucn)
4. Gihmxydng(buildout)ccmoduleconvhonthnhmodulechnh.
5.
Gi
hm
to
cc
gi
tin
ch
ng
(activation
message)
cho
mi
module
n.Vd:
//findfactoryobjectcModuleType*moduleType=findModuleType("WirelessNode");
//create(possiblycompound)moduleandbuilditssubmodules(ifany)
-
7/31/2019 Gioi Thieu Ve Omnet++
53/82
OMNet++
Trang53
cModule*module=moduleType->create("node",this);module->buildInside();
//createactivationmessagemodule->scheduleStart(simTime());Hymodulemodule->deleteModule(); ToccktnisrcGate->connectTo(destGate); To2modulevktnichngvinhau:cModuleType*moduleType=findModuleType("TicToc"); cModule*a=modtype->createScheduleInit("a",this);cModule*b=modtype->createScheduleInit("b",this);
a->gate("out")->connectTo(b->gate("in")); b->gate("out")->connectTo(a->gate("in")); HyktnisrcGate->disconnect();
-
7/31/2019 Gioi Thieu Ve Omnet++
54/82
OMNet++
Trang54
6. MESSAGE
6.1.Message
v
Packet
6.1.1.LpcMessagecMessagelmtlp trungtmcaOMNeT++.itngca lpcMessagevcclpconcancthmhnhhocrtnhiuitngnhccmessage,ccgitin(packet),frame,cell,bit,cctnhiutruyntrongmng,ccthcthtruyntrongmththng...
ThuctnhMtitngcalpcMessagecmtsthuctnh,mtscsdngbiphnnhnmphng,mtskhcccungcpchongilptrnh.
Tn-name: thuc tnh lmtchui(constchar*)mngilp trnhcthsdngtu.TncamessagexuthinrtnhiunitrongTkenvvnncchncngha.ThuctnhnykthatlpcObject.
Kiu message - message kind: thuc tnh ny cha thng tin v kiu camessage.
di-length(c tnh theobit):csdng tnh trkhimessagec truyn thngquamtktnic tc truynd liucgngi trxcnh.
Cbit li -bit error flag: thuc tnh ny c thit lpbng truebiphnnhnmphngvixcsutbng1-(1-ber)lengthkhimessagecgithng
quamtktnictctruyndliuxcnh(ber). Quynu tin -priority:c sdngbiphnnhnmphng spxp
ccmessage trong danh sch hng i (message queue -FES) c cng thigianti.
Mcthigian-timestamp:thuctnhnychophpngisdngnhduthigianvdnhnhduthiimmessagecxpvohngihoccgili.
Cc thuc tnhkhcvcc thnhphnd liugipchongi lp trnh lmvicddnghnnh:danhsch thams (parameter list),messagenggi(encapsulated message), thng tin iu khin (control info) v con tr ngcnh(contextpointer.
Mt s cc thuc tnh ch c (read-only attribute) lu gi cc thng tin vvicgimessage,ccthngtinvccmodule,cngngunvch,thigiangivthigianticaccmessage.HuhtccthuctnhnyucsdngbiphnnhnmphngkhiccmessagenmtrongFES,tuynhinkhiccmodulenhncmessage,ccthngtinnyvncntnti.
Cchsdng
-
7/31/2019 Gioi Thieu Ve Omnet++
55/82
OMNet++
Trang55
HmkhitocalpcMessagecthnhnmtviis.Thngthng,mtitngca lpcMessagesnhnvohaiis l tn(kiustring)vkiumessage(kiuint):
cMessage*msg=newcMessage("MessageName",msgKind);
Ttcccisultuchn,dokhaibomtitngnhsaucnghpl
cMessage*msg=newcMessage();
hay
cMessage*msg=newcMessage("MessageName");
Khikhngcis,mcnhitngmitoractnlvkiul0.Hmtoca lpcMessagec thnhnvonhiui shn (length,priority,biterror flag),tuynhintgitrchoccthuctnhtacngkhngnhtthitphisdnghmto.Tacthsdnghmset...()gngitrchotngthuctnh.
msg->setKind(kind);
msg->setLength(length);
msg->setPriority(priority);msg->setBitError(err);
msg->setTimestamp();
msg->setTimestamp(simtime);
Ngoiratacthsdngcchmsaulygitrcaccthams:
intk=msg->kind();
intp=msg->priority();
intl=msg->length();
boolb=msg->hasBitError();simtime_tt=msg->timestamp();
NhnimessageTacththchinsaochpmtmessagebngcch:
cMessage*copy=(cMessage*)msg->dup();
hoc
cMessage*copy=newcMessage(*msg);
Cchny c thpdngvibtkmti tngno trongOMNeT++.Messagemictolmtbncopychnhxccamessagec,baogmcccthams...
6.1.2.Self-MessageSdngself-messageCcmessage thng c s dng m t cc s kin xy rabn trong camtmodule.Trongmts trnghp,messagecthcoinhmtbnh thidngxcnhthiimdinramtskinno.Nhngmessagesdngtrongnhng
-
7/31/2019 Gioi Thieu Ve Omnet++
56/82
OMNet++
Trang56
trnghpnhvycgilself-message.Tuynhinself-messagevnlmessagebnhthng,lmtitngcalpcMessagehocmtlpconkthatn.
Khimtmessagecphnnmtmodulebiphnnhnmphng,bncthgihmisSelfMessage()kimtraxemncphilmtself-messagehaykhng;nimt cch khc l kim tra xem message nhn c cphi l mt scheduledmessage(ccmessagedngnhthiimdinramtskintrongmodule)haylccmessagecgibimthmsend...()no.Ngoirangisdngcths dng hm isScheduled() kim tra, hm ny s tr v true numessage nhnc l mt scheduled message (nhng message c xc nh bi hmscheduleAt()).MtscheduledmessagecngcthbhubbihmcancelEvent().
boolisSelfMessage();
boolisScheduled();
Cchmsautrvthigianto,thitlpvthigianticamtmessage.simtime_tcreationTime()
simtime_tsendingTime();
simtime_tarrivalTime();Khimtself-messagecthitlp, thigian ticamessages l thigiannscchuyntimodulecnthit.
Contrngcnh(ContextPointer)XthaihmsetContextPointer()vcontextPointer():
HmsetContextPointer()nhnmtcon trngcnh (kiuvoid) lmis thitlpngcnhchomessage.
HmcontextPointer()trvmtcontrkiuvoid,changcnhcamessagetngng.
void*context=...;
msg->setContextPointer(context);
void*context2=msg->contextPointer();
Ngilptrnhcthsdngcontrngcnhchonhiumcchvphnnhnmphng khng can thip n con tr ny. Tuy nhin trn thc t, con tr ng cnhthngc sdngkhimtmodule thit lpmtvi self-message (bnh thi),modulescnphixcnhckhinomtself-messagequaylimodule,haynimtcchkhcncnphixcnhckhinobnhthihotngvphilmgsau.Khicontrngcnhsctoratrtimtcutrcdliucamodule,mangythngtinngcnhvskinspdinra.
6.1.3.MhnhhogitinCngnhnvthigianticamtmessageCchmchravtrnhnvgicamtmessage:
intsenderModuleId();
intsenderGateId();
-
7/31/2019 Gioi Thieu Ve Omnet++
57/82
-
7/31/2019 Gioi Thieu Ve Omnet++
58/82
-
7/31/2019 Gioi Thieu Ve Omnet++
59/82
OMNet++
Trang59
giiphngchngkhichngbxakhidanhsch.Nhngvicnyc thchinqua hai hm take() v drop(). V d thm vo lp mt std::list c gi lmessageschadanhschcccontrmessage,bnnnthmonmsau:
voidMessageBundleMessage::insertMessage(cMessage*msg)
{
take(msg);//takeownership
messages.push_back(msg);//storepointer
}
voidMessageBundleMessage::removeMessage(cMessage*msg)
{
messages.remove(msg);//removepointer
drop(msg);//releaseownership
}
Bncngcnphithmvomthmoperator=()mboccitngmessagecabncthcsaochphocnhni(ylnhngiurtcnthittrongqutrnhmphng).
6.1.5.ThmitngvthamsThmitngLpcMessagecitngcArraycthchaccitngkhc.TuynhinchccitngkthatlpcObject(huhtcclptrongOMNeT++ukthatlpny) mi c th c thm vo cc message. Cc hm addObject(), hasObject(),removeObject()nhntncaccitngnhcckhotruynhpmng.Vd:
cLongHistogram*pklenDistr=newcLongHistogram("pklenDistr");msg->addObject(pklenDistr);
...
if(msg->hasObject("pklenDistr"))
{
cLongHistogram*pklenDistr=
(cLongHistogram*)msg->getObject("pklenDistr");
...
}
Bnphicn thn khi thmmti tngvomessage, trnhxy ra tnh trngxungtgiaccitngbtrngtn.NubnkhnggnkmmtitngnovomessageanhkhnggihmparList(),itngcArrayskhngcto.
Bn cng c th thmvomessage cci tngkhng k tha t cObject (non-cObjectobject)bngcchsdngcontrcalpcPar.Vd:
structconn_t*conn=newconn_t;//conn_tisaCstruct
-
7/31/2019 Gioi Thieu Ve Omnet++
60/82
OMNet++
Trang60
msg->addPar("conn")=(void*)conn;
msg->par("conn").configPointer(NULL,NULL,sizeof(structconn_t));
ThmthamsPhngphpttnhtmrngccmessagevinhngtrngdliumilnh
ngha
cc
message
(xem
phn
5.2).
Tuynhin tac th sdngmtphngphpkhc (khngckhuynkhch)thmcctrngdliumichomessagethngquaccitngcPar.Nhcimcaphngphpny l tnbnhv thigian thchinchm.Cci tngcacParthngckch thclnvkhphctp.MtkhckhisdngccitngcParcngrtdsinhralibiccitngnyphicthmvongvclpivimiitngmessage.
TuynhinnubnvncnsdngcPar,nscungcpchobnmtshmcbn.HmaddPar()cdngthmmtthamsmichomessage.HmhasPar()kimtra xemmtmessage c cc tham s hay khng.Cc tham s camessage c thc truynhp thngquachscamng thams.HmfindPar() trvchsca
mtthamsvtrv-1nuthamskhngtnti.Ccthamscngcthctruynhpbngcchvitchnghmpar().Vd:
msg->addPar("destAddr");
msg->par("destAddr")=168;
...
longdestAddr=msg->par("destAddr");
6.2.nhnghamessage6.2.1.GiithiuTrongthct,bnsphithmrtnhiutrngvolpcMessagelmchonddnghn.Lyvd,nubnmhnhhoccgitintrongmtmngthngtin,bncnccchluphnheadercagiaothctrongccitngmessage.Mtcchtnhin,chng ta thyrngthvinmphngcaOMNeT++cvittrnngnngC++,dothmcctrngmivolpcMessagetacthtocclpconkthatlpcMessagevthmcctrngvonhnhngthnhphnringcalpcon.Tuynhin,domitrngmbnthmvoucntnht3thnhphn(dliuthnhphn ring,hmset() thit lpgi trvhmget() trvgi tr)v lpmicnphictchhpvinntngmphngnnvicsdngC++thcslmtcngvicbuntvmtthigian.
OMNeT++cungcpchongisdngmtphngphplmvichiuquhn,lnhnghaccmessage.Nhngnhnghanysdngmtcphprtngngnm tnidungcaccmessage.MC++s tngsinhradavonhngnhnghanyvbnhontonckhnngsalinhngoncodechothchhpvtngcabn.
Lpmessageutin
-
7/31/2019 Gioi Thieu Ve Omnet++
61/82
OMNet++
Trang61
Taxtmtvdngin.Gisrngbncnccitngmessagephicthmachcangun,chvbmbctruyn,bncthvitmtfilemypacket.msgnhsau:
messageMyPacket
{
fields:
int srcAddress;
intdestAddress;
inthops=32;
};
Nubnbindchfilemypacket.msg,trnhbindchstngsinhrahaifileC++tngngc tn lmypacket_m.hv filemypacket_m.cc.Filemypacket_m.hchacckhaibocalpMyPacket(lpC++tngngvinhnghamessagetrongfilemypacket.msg)vbncthtfilenyvotrongmC++iukhinhotng
ca
i
tng
MyPacket.
Filemypacket_m.hschacckhaibolpnhsau:
classMyPacket:publiccMessage
{
...
virtualintgetSrcAddress()const;
virtualvoidsetSrcAddress(intsrcAddress);
...
};
DotrongfileC++bncthsdnglpMyPacketnhsau:
#include"mypacket_m.h"
...
MyPacket*pkt=newMyPacket("pkt");
pkt->setSrcAddress(localAddr);
...
File mypacket_m.cc cha cc trin khai ca lpMyPacket chophpbn kim tranhngcu trcd liu tronggiaodincaTkenv(TkenvGUI).Filemypacket_m.cc
nn
c
bin
dch
v
thit
lp
lin
kt
vi
m
hnh
m
phng
ca
bn
(nu
bn
sdngcngcopp_makemake toccmakefiles, thcccngvic linquannfile.ccstngcthchin).
Khinim-nhnghamessageC nhiu kin khng r rng v mc ch cng nh khi nim v nh nghamessage.Tuynhinchng taphixcnh r rng rng,nhnghamessagekhng
phil:
-
7/31/2019 Gioi Thieu Ve Omnet++
62/82
OMNet++
Trang62
... scgngmphngccchcnngcaC++nhngvimtcphpkhc.Chnginvicnhnghamessagechlxcnhccdliu(hayxcnhmtgiaotiptruynhptidliu)chkhngphilbtkmtkiuthuctnhno.
...mtcngcsinhm.iunychngvivicnhnghanidungcamessagevcccu trcd liumbn sdng trongmessage.Vicnhnghacchmkim sot hot ng camessage khng c h tr.Hn na c vic s dng c
phpnysinhracclpvcccu trcbntrongcaccmodulengincngkhngckhuynkhch.
6.2.2.Sdngenumenum{...}sdng trongkhainhnghamessagescchuyn thnhkiuenumthcs trongC++.y lmti tngdngchaccgi tr textidinchocchng s. Vic sdng enumchophp hin th tn didngbiu tng trongTkenv.
Vd:
enumProtocolTypes
{
IP=1;
TCP=2;
};
Ccgitrtrongenumphilduynht.
6.2.3.KhitochomtmessageCchkhitocbnBn
c
th
m
t
mt
message
theo
c
php
sau:
messageFooPacket
{
fields:
intsourceAddress;
intdestAddress;
boolhasPayload;
};
Trnhbin dch s dch onm t trn thnhmt fileC++ vimt lp c tn lFooPacket.FooPacketny s lmt lpconca lpcMessage.ivimi trngtrongonkhaibotrn,tronglpC++tngngcngscmtthnhphndliuring,mthmsettervmthmgetter.DoFooPacketscnhnghmsau:
virtualintgetSourceAddress()const;
virtualvoidsetSourceAddress(intsourceAddress);
virtualintgetDestAddress()const;
virtualvoidsetDestAddress(intdestAddress);
-
7/31/2019 Gioi Thieu Ve Omnet++
63/82
OMNet++
Trang63
virtualboolgetHasPayload()const;
virtualvoidsetHasPayload(boolhasPayload);
Ch lttccchm trnuckiu lvitual, tclbnckhnng thchinchnghmcclpcon.
Haihmtocngcsinhra:mtnhptnitngvkiumessagevmtl
hmtosaochp(tomtitngmilbnsaocaitngc).
FooPacket(constchar*name=NULL,intkind=0);
FooPacket(constFooPacket&other);
Ngoira trnhbindchcng tngsinh ra trong lpcchmnhoperator=()vdup()(cchmdngsaochpvnhnbnitng).
Bncthsdngcckiudliudiykhaibochocctrngtrongnhnghamessage:
bool
char, unsigned char
short,unsignedshort
int,unsignedint
long,unsignedlong
double
Gitrkhitocacctrngmcnhbng0.
GitrkhitoBncthkhitogitrchocctrngtrongmtmessagetheocphpsau:
messageFooPacket
{
fields:
intsourceAddress=0;
intdestAddress=0;
boolhasPayload=false;
};
PhnmkhitotrongonkhaibotrnscthaythbicchmtotrongcclpC++.
KhaibokiuenumBnc thkhaibocc trngkiu int (haycckiu snguynkhc)nhngi trtrongmtenum.Trongtrnghpsdngenum,trnhbindchcthsinhmcho
phpTkenvhinthgitrcatrngdidngccbiutng.
Vd:
messageFooPacket
{
-
7/31/2019 Gioi Thieu Ve Omnet++
64/82
OMNet++
Trang64
fields:
intpayloadTypeenum(PayloadTypes);
};
Kiuenumphickhaiboringrtrongfile.msg.
MngkchthccnhCthsdngccmngckchthccnh:
messageFooPacket
{
fields:
longroute[4];
};
Trongtrnghpnycchmgettervsetterscthmmtthamsphlchscamng.
virtuallonggetRoute(unsignedk)const;
virtualvoidsetRoute(unsignedk,longroute);
MngngmessageFooPacket
{
fields:
longroute[];
};
Trongtrnghpny,lpC++csinhrascthmhaihm,ngoicchmsettervgetterbnhthng.Mthmtkchthccamngvhmcnlitrvkchthchinticamng.
virtuallonggetRoute(unsignedk)const;
virtualvoidsetRoute(unsignedk,longroute);
virtualunsignedgetRouteArraySize()const;
virtualvoidsetRouteArraySize(unsignedn);
Hm set...ArraySize()cpphtbnhchomtmngmi.Ccgi tr tn ti trongmngscduytr(csaochpsangmtmngmi).
Kch thcmc nh camng l 0.iu ny c ngha lbn cnphi gi hmset...ArraySize()trckhibncthbtunhpccphntcamng.
Chui
messageFooPacket
{
fields:
-
7/31/2019 Gioi Thieu Ve Omnet++
65/82
OMNet++
Trang65
stringhostName;
};
Cchmgettervsetterscdngnhsau:
virtualconstchar*getHostName()const;
virtual
void
setHostName(const
char
*hostName);
Ch:mtchuikhcvimtmngk t.Mngk tccoinh lmtmngthngthng.
Vd:
messageFooPacket
{
fields:
charchars[10];
};
Cchmgettervsettertngngsl:
virtualchargetChars(unsignedk);
virtualvoidsetChars(unsignedk,chara);
6.2.4.QuanhkthavhpthnhNhngphntrnnivvicthmcctrngdliucbn(int,double,char,...)vomtmessage.ivinhngmodulenginnhvy lkh tuynhinivinhngmodulephctp,bncncn:
Thitlpcutrcphncpchocclpmessage,nghalcclpmessagekhngchkthatlpcMessagemcncthkthatnhnglpdobntora.
Cctrngdliutrongmessagekhngchlnhngkiudliucbnmncnc th lcccu trc (struct),cc lphoccckiud liudongidng tnhngha.
QuanhkthagiacclpmessageMcnh,cclpmessageulcclpconkthatlpcMessage,tuynhinbncthsdngmtlpcskhcthngquatkhoextends
messageFooPacketextendsFooBase
{
fields:
...
};
Theovdny,lpC++tngngscdngnhsau:
classFooPacket:publicFooBase{...};
Khaibolp
-
7/31/2019 Gioi Thieu Ve Omnet++
66/82
OMNet++
Trang66
Cphpkhaibomtlpcngtngtnhcphpkhaibomtmessagechkhcnhautkha,classthaychomessage.
classMyClassextendscObject
{
fields:
...
};
ChrngnukhaibomtlpmkhngctkhoextendsthlpctoraskhngckthatlpcObject.Dotronglpskhngcmtshmnhname(),nameClass(),...tomtlpcynhnghmnynhtthithmphickhaiboextendscObject.
KhaibocutrcBncthtocccutrckiuCsdngnhcctrngdliutrongcclpmessage.CutrckiuCcnghalchchadliuvkhngchm(trongthc
tthcutrctrongC++cthchacchm).Cphpkhaibostruct:
structMyStruct
{
fields:
chararray[10];
shortversion;
};
Cphpkhaibonycngtngtnhcphpkhaibomessage.TuynhinphnmC++sinhralikhcnhau.Cccutrcctngsinhraskhngccchmsetter v getter, thay vo cc thnhphn d liu ca struct c kiu truy xut l
public(ccdliuthnhphntrongmessageckiutruyxutlprivate-khngchophp truy xut tbn ngoi).i vion khaibo trn,phnm sinh ra s cdngnhsau:
//generatedC++
structMyStruct
{
chararray[10];
shortversion;
};
Cctrngcamtstructcthckiudliucbnhoclmtstructkhcnhng nkhngthckiuchuihocchamtlp.
Quanhkthacngchtriviccstruct:
structBase
-
7/31/2019 Gioi Thieu Ve Omnet++
67/82
OMNet++
Trang67
{
...
};
structMyStructextendsBase
{
...
};
Bivmtcutrckhngchacchmthnhphn,doncmtsgiihn:
Khnghtrccmngng(khngthkhaibocchmcpphtbnhchomng).
Cc trng tru tng (generation gap)khngc s dng,biv chngcxydngdatrncchmo.Khinimtrng trutng(abstractfield)scmtphnsau.
SdnglpvcutrctrongmessageNubncmtcutrckhaiboctnlIPAddress,bncthsdngntrongmessagenhsau:
messageFooPacket
{
fields:
IPAddresssrc;
};
CutrcIPAddressphickhaibotrctrongfile.msghocnphilmtkiuC++(xemphnAnnouncingC++types).
Cchmgettervsettertngng:
virtualconstIPAddress&getSrc()const;
virtualvoidsetSrc(constIPAddress&src);
6.2.5.SdngcckiucsncaC++Nubnmunsdngcckiud liu tmnhnhngha trongccmessage,bncnphithngbokiudliuvitrnhbindchmessage.
GisbnckhaibomtcutrcctnIPAddresstrongfileipaddress.h:
//ipaddress.h
structIPAddress
{
intbyte0,byte1,byte2,byte3;
};
c thsdng IPAddress trongmessage, filemessage(c tn lfoopacket.msg)nnchaonmsau:
-
7/31/2019 Gioi Thieu Ve Omnet++
68/82
OMNet++
Trang68
cplusplus
{{
#include"ipaddress.h"
}};
struct
IPAddress;
Tc dng ca ba dng u tin ch n gin l sao chp cu lnh #includeipaddress.hvo trong file foopacket_m.h trnhbindchbitv lp IPAddress.Trnhbindchskhngcgngkimtranghacaccontextnmtrong thncakhaibocplusplus{{...}}.DngtiptheoschrchotrnhbindchIPAddresslmtcutrc.Nhngthngtinnysnhhngnphnmcsinhra.
Tngtnhvytrongtrnghpbnmunsdngmtlptrongmessage,gistnlplsSubQueuethdngcuicngtrongonkhaibobnilil:
classcSubQueue;
Cphp trnc sdng trong trnghpcc lpu l lp con trc tip hoc
gin
tip
ca
lp
cObject.
Nu
mt
lp
khng
c
quan
h
tha
k
vi
lp
cObject
thbnphi s dng thm t kho noncobject (nu khng trnhbin dchmessage snhmvfilectorasgyralikhibindchbngtrnhbindchcaC++):
classnoncobjectIPAddress;
6.2.6.ThayiccfileC++MuGenerationGapikhibncncconmtsinhracththchincnhiuhnhockhcisovinhnggmtrnhbindchtothnh.Lyvd,khitmttrngsnguynctnlpayloadLength,cthbnscnchnhsachiudicagitin.Tuynhin
on
m
t
sinh
ch
cha
hm
setPayloadLength(),
iu
ny
khng
thch
hp
pngyucutra.
voidFooPacket::setPayloadLength(intpayloadLength)
{
this->payloadLength=payloadLength;
}
tho mnyucu,hmsetPayloadLength()nncdngnhsau:
voidFooPacket::setPayloadLength(intpayloadLength)
{
intdiff=payloadLength-this->payloadLength;
this->payloadLength=payloadLength;
setLength(length()+diff);
}
Bnhthng,nhcimlnnhtca vicsinhmtnglskhkhnkhithomccyucucangisdng.Vicchnhsabngtayliccfiletngnyl
-
7/31/2019 Gioi Thieu Ve Omnet++
69/82
-
7/31/2019 Gioi Thieu Ve Omnet++
70/82
OMNet++
Trang70
FooPacket&operator=(constFooPacket&other)
{ FooPacket_Base::operator=(other)
; return*this;
}
virtual
cObject
*dup()
{
returnnewFooPacket(*this);
}
};
Register_Class(FooPacket);
Quaytrvvivdvthayichiudigitin,tacthvitonmnhsau:
classFooPacket:publicFooPacket_Base
{
//herecomethemandatorymethods:constructor,
//copycontructor,operator=(),dup()
//...
virtualvoidsetPayloadLength(intnewlength);
}
voidFooPacket::setPayloadLength(intnewlength)
{
//adjustmessagelength
setLength(length()-getPayloadLength()+newlength);
//setthenewlength
FooPacket_Base::setPayloadLength(newlength);
}
TrngtrutngMcchcatrngtrutnglchophpngisdngcthvitchnglicchthcgitrcatrngclutrbntronglp.Bncthkhaibobtktrngnoltrngtrutngvicphpsau:
messageFooPacket{
properties:
customize=true;
fields:
-
7/31/2019 Gioi Thieu Ve Omnet++
71/82
OMNet++
Trang71
abstractboolurgentBit;
};
Vimttrngtrutng,trnhbindchstoramtthuctnhcalpkhngcd liu thnhphnvcchmgetter/setters tr thnhcchmthuno (cchmthunolcchmkhngcthnhm):
virtualboolgetUrgentBit()const=0;
virtualvoidsetUrgentBit(boolurgentBit)=0;
6.2.7.SdngSTLtrongcclpmessageVicsdngcctrngtrutngcnchophpngisdngcthdngcclpvectorhocstacktronglpmessage.
Xtnhnghamessagediy:
structItem
{ field
s: int
a;
doubleb;
}
messageSTLMessage
{
properties:
customize=true;
fields:abstractItemfoo[];//willusevector
abstractItembar[];//willusestack
}
Nubnbindchonkhaibo trn,phnmsinhraschbaogmmtcphmtngngvihai trng foovbar,khngc thnhphnd liuvkhngchmnockhaiboc th.Bnc th thayi limi th,c th trinkhai liccthuctnhfoovbarvikiustd::vectorvstd::stack:
#include
#include
#include"stlmessage_m.h"
classSTLMessage:publicSTLMessage_Base
{
-
7/31/2019 Gioi Thieu Ve Omnet++
72/82
OMNet++
Trang72
protected:
std::vector foo;
std::stack bar;
public:
STLMessage(const
char
*name=NULL,
int
kind=0)
:
STLMessage_Base(name,kind)
{}
STLMessage(const STLMessage& other) : STLMessage_Base(other.name()){operator=(other);}
STLMessage&operator=(constSTLMessage&other){
if(&other==this)return*this;
STLMessage_Base::operator=(other);
foo=other.foo;
bar=other.bar;
return*this;}
virtualcObject*dup(){returnnewSTLMessage(*this);}
//foomethods
virtualvoidsetFooArraySize(unsignedintsize){}
virtualunsignedintgetFooArraySize()const{returnfoo.size();}
virtualItem&getFoo(unsignedintk){returnfoo[k];}
virtualvoidsetFoo(unsignedintk,constItem&afoo){foo[k]=afoo;}
virtual
void
addToFoo(const
Item&
afoo)
{foo.push_back(afoo);}
//barmethods
virtualvoidsetBarArraySize(unsignedintsize){}
virtualunsignedintgetBarArraySize()const{returnbar.size();}
virtualItem&getBar(unsignedintk){thrownewcRuntimeException("sorry");}
virtualvoidsetBar(unsignedintk,constItem&bar)
{thrownewcRuntimeException("sorry");}
virtualvoidbarPush(constItem&abar){bar.push(abar);}
virtualvoidbarPop(){bar.pop();}
virtualItem&barTop(){returnbar.top();}
};
Register_Class(STLMessage);
Mtsch:
CchmsetFooArraySize(),setBarArraySize()ltha.
-
7/31/2019 Gioi Thieu Ve Omnet++
73/82
OMNet++
Trang73
HmgetBar(intk)khngthctrinkhaivkiustackkhngchophptruynhpccphnttheochs.
HmsetBar(intk,constItem&)cngkhngctrinkhaicngvildonhtrn.
-
7/31/2019 Gioi Thieu Ve Omnet++
74/82
OMNet++
Trang74
7. CHY CC NG DNG OMNeT++Nh trnhbyphnm u,mth thngmngmphng trongOMNeT++
gmccthnhphnsau:
Ccfile.nedmttopomng.
Ccfilecphnmrng.msgchakhaiboccmessage
CcfileC++(cphnmrngl.cctrongUNIXhoc.cpptrongWindows)
Qutrnhxydngmtchngtrnhmphng:
u tin, dch cc fileNED v cc filemessage thnhC++, s dngNEDcompiler(nedc)vmessagecompiler(opp_msgc).
QutrnhtiptheogingnhbindchmngunC/C++:
oTrong
Linux:
cc
file
.cc
file
.o.
o TrongWindows:ccfile.cppfile.obj.o Sau,ttcccfiletrnsclinkt(link)viccthvincn
thittothnhfile.exe.
Cth,tacnphilinktviccthvinsau:
Phn nhn m phng c gi l sim_std (nh cc file libsim_std.a,sim_std.lib,etc).
Giaodinngidng:cung cp thvinmi trng (file libenvir.a, etc)vcc tin ch tkenv v cmdenv (libtkenv.a, libcmdenv.a, etc). Cc file .o(hoc .obj)phi c lin kt ti th vinmi trng cng vi hoc tkenv
hoccmdenv.
Hnhdiychochngtahnhnhqutrnhxlkhimhnhcxydngvhotng.
-
7/31/2019 Gioi Thieu Ve Omnet++
75/82
OMNet++
Trang75
HnhI-7.1-Qutrnhxydngvthchinmhnh
7.1SdnggccToMakefile:
Saukhixydngxongccfilengun*.ned,*.msg,*.cc,*.htrongcng1thmchyg
%opp_makemakeLnhnystorafilectnlMakefile.Saugtipmaketofilechy.Tncafilechynystrngvitnthmcchaccfilengun.
7.2SdngMicrosoftVisualC++
TngtnhtrongUNIX.Nugopp_nmakemaketrongthmcchaccfilengun*.ned,*.msg,*.cpp,*.hthstorafileMakefile.vc.opp_nmakemake
tofilechy,tag
nmake-fMakefile.vc
-
7/31/2019 Gioi Thieu Ve Omnet++
76/82
OMNet++
Trang76
8. M HNHN GIN - TICTOCminhhacchmphngmngbngOMNeT++,tasbtuvi1mngrtn
gin,chgm2nttraoidliu:1nttoragitinvntth2nhnvgitrligitinny. Chngtagi2ntnyl"tic"v"toc".
Ccbcxydngngdngtrn:
1.To1thmctnltictocvcdtithmcny.
2.Tofiletopomng.ttnltictoc1.ned:
simpleTxc1gates:in:in;out:out;
endsimple
////Twoinstances(ticandtoc)ofTxc1connectedbothways.//Ticandtocwillpassmessagestooneanother.//moduleTictoc1submodules:tic:
Txc1;
toc:Txc1;
connections:tic.out-->delay100ms-->toc.in;tic.in
-
7/31/2019 Gioi Thieu Ve Omnet++
77/82
OMNet++
Trang77
Tictoc1l1moduletnghp,gm2submodules,ticvtoc.2modulethnhphnnyulccitngcamoduleckiuTxc1.Sau,taktnicngracaticticngvocatocvngcli.trkhitruyn l100ms.
Txc1l1modulen(tclnccpthpnhttrongNEDfilevcvitbngC++).Txc1c1cngvotnlinv1cngrattnlout
(simple..
endsimple).
3.C++filetxc1.cc(UNIX)hoctxc1.cpptrongWindows#include#includeclassTxc1:publiccSimpleModule{//Thisisamacro;itexpandstoconstructordefinition.Module_Class_Members(Txc1,cSimpleModule,0);//Thefollowingredefinedvirtualfunctionholdsthealgorithm.virtualvoidinitialize();virtualvoidhandleMessage(cMessage*msg);
};
//ThemoduleclassneedstoberegisteredwithOMNeT++Define_Module(Txc1);
voidTxc1::initialize(){//Initializeiscalledatthebeginningofthesimulation.//Tobootstrapthetic-toc-tic-tocprocess,oneofthemodulesneeds//tosendthefirstmessage.Letthisbe`tic'.
//AmITicorToc?if(strcmp("tic",name())==0){//createandsendfirstmessageongate"out"."tictocMsg"isan//arbitrarystringwhichwillbethenameofthemessageobject.cMessage*msg=newcMessage("tictocMsg");send(msg,"out");
}
-
7/31/2019 Gioi Thieu Ve Omnet++
78/82
-
7/31/2019 Gioi Thieu Ve Omnet++
79/82
OMNet++
Trang79
6.Munchyc,tacnphitofileomnetpp.inibochotrnhmphngbittamunchymphngivimngno.iunycngcnghanhiumngcthchung1trnhmphng.
Fileomnetpp.initrongvdnycngrtngin
[General]
network=tictoc1
7.Sau,tasbtuchyngdngbnglnh:
-UNIX
$./tictoc
-Windows
>tictoc
Tasthycasmphnghinra
-
7/31/2019 Gioi Thieu Ve Omnet++
80/82
OMNet++
Trang80
ClickOK
8.NhnntRunbtuqutrnhmphngthy2ntmngtraoiccgitinchonhau.
Caschnhhinththigianmphng.Nhinthiimngvimilntruyntin.
9.Tacthhiuchnhchchy:dng-F8(STOPbutton),chytngbcF4) Vd:Stepmode
-
7/31/2019 Gioi Thieu Ve Omnet++
81/82
OMNet++
Trang81
10.MunthotchcnnClosehocchnFile|Exit.
-
7/31/2019 Gioi Thieu Ve Omnet++
82/82
OMNet++