RINASim  October 2016
Documentation of framework for OMNeT++
DA.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #include "DA.h"
24 
26 
27 const APNList* DA::findApnNeigbors(const APN& apn) {
28  return NeighborTab->findNeighborsByApn(apn);
29 }
30 
32  Enter_Method("resolveApnToBestAddress()");
33 
34  DirectoryEntry* de = resolveApn(apn);
35  if (de == NULL) {
36  EV << "DA does not know target application" << endl;
37  return NULL;
38  }
39 
40  //Return first local DIF address
41  for (AddrCItem it = de->getSupportedDifs().begin(); it != de->getSupportedDifs().end(); ++it) {
42  if (isDifLocal(it->getDifName()))
43  return &(*it);
44  }
45 
46  EV << "None of found DIFs is local!" << endl;
47  return NULL;
48 }
49 
50 const Address* DA::resolveApnToBestAddress(const APN& apn, const DAP& difName) {
51  Enter_Method("resolveApnToBestAddress()");
52 
53  DirectoryEntry* de = resolveApn(apn);
54  if (de == NULL) {
55  EV << "DA does not know target application" << endl;
56  return NULL;
57  }
58 
59  //Return address from a given DIF
60  for (AddrCItem it = de->getSupportedDifs().begin(); it != de->getSupportedDifs().end(); ++it) {
61  if (it->getDifName() == difName && isDifLocal(it->getDifName()))
62  return &(*it);
63  }
64 
65  EV << "None of found DIFs is local!" << endl;
66  return NULL;
67 }
68 
69 const APNList* DA::findNeigborApns(const APN& neighbor) {
70  return NeighborTab->findApnsByNeighbor(neighbor);
71 }
72 
74  //Retrieve pointers to submodules
75  Dir = getRINAModule<Directory*>(this, 1, {MOD_DIRECTORY});
76  NamInfo = getRINAModule<NamingInformation*>(this, 1, {MOD_NAMINFO});
77  NeighborTab = getRINAModule<NeighborTable*>(this, 1, {MOD_NEIGHBORTABLE});
78  SearchTab = getRINAModule<SearchTable*>(this, 1, {MOD_SEARCHTAB});
79 }
80 
82 {
83  //Retrieve pointers to submodules
84  initPointers();
85 }
86 
93 bool DA::isDifLocalToIpc(const std::string difName, cModule* ipc) {
94  cModule* top = ipc->getParentModule();
95  for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
96  cModule *submodp = j();
97  if (isIpcXLocalToIpcY(submodp, ipc)
98  && !opp_strcmp(submodp->par(PAR_DIFNAME), difName.c_str()) //...has a given DIF name
99  )
100  return true;
101  }
102  return false;
103 }
104 
111 bool DA::isIpcXLocalToIpcY(cModule* ipcX, cModule* ipcY) {
112  //Both of them have same parent module
113  //...AND both of them are IPC (has IPCAddress parameter)
114  return ipcX->getParentModule() == ipcY->getParentModule()
115  && ipcX->hasPar(PAR_IPCADDR) && ipcX->hasPar(PAR_DIFNAME)
116  && ipcY->hasPar(PAR_IPCADDR) && ipcY->hasPar(PAR_DIFNAME);
117 }
118 
119 bool DA::isAppLocal(const APN& apn) {
120  cModule* top = this->getModuleByPath("^.^");
121  for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
122  cModule* submodp = j();
123  if ( (submodp->hasPar(PAR_APNAME)
124  && !opp_strcmp(submodp->par(PAR_APNAME), apn.getName().c_str() ) )
125 // ||
126 // (submodp->hasPar(PAR_IPCADDR)
127 // && !opp_strcmp(submodp->par(PAR_IPCADDR), apn.getName().c_str() ) )
128  )
129  return true;
130  }
131  return false;
132 }
133 
134 bool DA::isDifLocal(const DAP& difName) {
135  cModule* top = this->getModuleByPath("^.^");
136  for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
137  cModule* submodp = j();
138  if (submodp->hasPar(PAR_DIFNAME)
139  && !opp_strcmp(submodp->par(PAR_DIFNAME), difName.getName().c_str())
140  ) {
141  //EV << "!!!!!" << difName << "!!!!!" << submodp->getFullPath() << endl;
142  return true;
143  }
144  }
145  return false;
146 }
147 
148 bool DA::isIpcLocal(cModule* ipc) {
149  cModule* top = this->getModuleByPath("^.^");
150  for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
151  cModule* submodp = j();
152  if (submodp == ipc)
153  return true;
154  }
155  return false;
156 }
157 
158 cModule* DA::getDifMember(const DAP& difName) {
159  cModule* top = this->getModuleByPath("^.^");
160  for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
161  cModule* submodp = j();
162  if (submodp->hasPar(PAR_DIFNAME)
163  && !opp_strcmp(submodp->par(PAR_DIFNAME), difName.getName().c_str())
164  )
165  return submodp;
166  }
167  return NULL;
168 }
169 
170 cModule* DA::findIpc(const Address& addr) {
171  cModule* top = this->getModuleByPath("^.^");
172  for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
173  cModule *submodp = j();
174  if (submodp->hasPar(PAR_IPCADDR) && submodp->hasPar(PAR_DIFNAME)) {
175  Address adr = Address(submodp->par(PAR_IPCADDR), submodp->par(PAR_DIFNAME));
176  if (adr == addr)
177  return submodp;
178  }
179  }
180  return NULL;
181 }
182 
183 FABase* DA::findFaInsideIpc(cModule* ipc) {
184  return dynamic_cast<FABase*>(ipc->getSubmodule(MOD_FLOWALLOC)->getSubmodule(MOD_FA));
185 }
186 
188  Enter_Method("resolveApn()");
189  APNList apns = NamInfo->findAllApnNames(apn);
190  //Return first Directory mapping from APN and all its synonyms
191  for (ApnCItem it = apns.begin(); it != apns.end(); ++it) {
192  DirectoryEntry* dre = Dir->findDirEntryByApn(*it);
193  if (dre)
194  return dre;
195  }
196  return NULL;
197 }
198 
199 void DA::handleMessage(cMessage *msg)
200 {
201 
202 }
203 
204 cModule* DA::findApp(const APN& apn) {
205  cModule* top = this->getModuleByPath("^.^");
206  for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
207  cModule *submodp = j();
208  if (submodp->hasPar(PAR_APNAME) && !strcmp(submodp->par(PAR_APNAME), apn.getName().c_str()) ) {
209  return submodp;
210  }
211  }
212  return NULL;
213 }
214 
215 
216 const Addresses* DA::resolveApnToAddressList(const APN& apn, const DAP& difName) {
217  Enter_Method("resolveApnToAddressList()");
218 
219  DirectoryEntry* de = resolveApn(apn);
220  if (de == NULL) {
221  EV << "DA does not know target application" << endl;
222  return NULL;
223  }
224 
225  Addresses* addrs = new Addresses();
226  //Return address from a given DIF
227  for (AddrCItem it = de->getSupportedDifs().begin(); it != de->getSupportedDifs().end(); ++it) {
228  if (it->getDifName() == difName && isDifLocal(it->getDifName()))
229  addrs->push_back(*it);
230  }
231 
232  if (addrs->empty()) {
233  EV << "None of found DIFs is local!" << endl;
234  }
235 
236  return addrs;
237 }
238 /*
239 cModule* DA::resolveApnToIpc(const APN& apn) {
240  Enter_Method("resolveApnToDif()");
241  DirectoryEntry* dre = Dir->findDirEntryByApn(apn);
242  return dre ? dre->getIpc() : NULL;
243 }
244 
245 FABase* DA::resolveApnToFa(const APN& apn) {
246  Enter_Method("resolveApnToDifFa()");
247  DirectoryEntry* dre = Dir->findDirEntryByApn(apn);
248  return dre ? dre->getFlowAlloc() : NULL;
249 }
250 
251 std::string DA::resolveApnToIpcPath(const APN& apn) {
252  Enter_Method("resolveApnToDifName()");
253  DirectoryEntry* dre = Dir->findDirEntryByApn(apn);
254  return dre ? dre->getIpcPath() : NULL;
255 }
256 
257 std::string DA::resolveApniToIpcPath(const APNamingInfo& apni) {
258  Enter_Method("resolveApniToDifName()");
259  //TODO: Vesely - Complete APNI search
260  return resolveApnToIpcPath(apni.getApn());
261 }
262 
263 cModule* DA::resolveApniToIpc(const APNamingInfo& apni) {
264  Enter_Method("resolveApniToDif()");
265  //TODO: Vesely - Complete APNI search
266  return resolveApnToIpc(apni.getApn());
267 }
268 
269 FABase* DA::resolveApniToFa(const APNamingInfo& apni) {
270  Enter_Method("resolveApniToDifFa()");
271  //TODO: Vesely - Complete APNI search
272  return resolveApnToFa(apni.getApn());
273 }
274 
275 DirectoryEntry* DA::resolveApni(const APNamingInfo& apni) {
276  return Dir->findEntryByApni(apni);
277 }
278 */
std::list< Address > Addresses
Definition: Address.h:146
const APNList * findNeigborApns(const APN &neighbor)
Definition: DA.cc:69
virtual void initialize()
Definition: DA.cc:81
const APNList * findApnNeigbors(const APN &apn)
Definition: DA.cc:27
const char * MOD_NEIGHBORTABLE
Definition: ExternConsts.cc:52
Application Process Name class.
Definition: APN.h:36
bool isDifLocalToIpc(const std::string difName, cModule *ipc)
Definition: DA.cc:93
const char * MOD_NAMINFO
Definition: ExternConsts.cc:51
NamingInformation * NamInfo
Definition: DA.h:91
Addresses::const_iterator AddrCItem
Definition: Address.h:147
cModule * findIpc(const Address &addr)
Definition: DA.cc:170
const char * PAR_IPCADDR
Definition: ExternConsts.cc:93
DirectoryEntry * findDirEntryByApn(const APN &apn)
Definition: Directory.cc:50
SearchTable * SearchTab
Definition: DA.h:93
bool isDifLocal(const DAP &difName)
Definition: DA.cc:134
std::list< APN > APNList
APNList represents the list of APNs.
Definition: APN.h:96
const char * PAR_APNAME
cModule * findApp(const APN &apn)
Definition: DA.cc:204
void initPointers()
Definition: DA.cc:73
const char * MOD_SEARCHTAB
Definition: ExternConsts.cc:65
NeighborTable * NeighborTab
Definition: DA.h:92
FABase * findFaInsideIpc(cModule *ipc)
Definition: DA.cc:183
const APNList * findNeighborsByApn(const APN &apn)
Directory * Dir
Definition: DA.h:90
const char * MOD_DIRECTORY
Definition: ExternConsts.cc:35
bool isAppLocal(const APN &apn)
Definition: DA.cc:119
virtual void handleMessage(cMessage *msg)
Definition: DA.cc:199
const char * MOD_FLOWALLOC
Definition: ExternConsts.cc:47
Definition: DA.h:43
const std::string & getName() const
Gets DAP string name representation.
Definition: DAP.cc:49
const APNList findAllApnNames(const APN &apn)
bool isIpcLocal(cModule *ipc)
Definition: DA.cc:148
const char * PAR_DIFNAME
Definition: ExternConsts.cc:94
const Addresses & getSupportedDifs() const
const Addresses * resolveApnToAddressList(const APN &apn, const DAP &difName)
Definition: DA.cc:216
Definition: FABase.h:33
APNList::const_iterator ApnCItem
APNList constant iterator.
Definition: APN.h:103
Define_Module(DA)
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
cModule * getDifMember(const DAP &difName)
Definition: DA.cc:158
const APNList * findApnsByNeighbor(const APN &neighbor)
const char * MOD_FA
Definition: ExternConsts.cc:46
Address class holds IPC Process identification.
Definition: Address.h:42
bool isIpcXLocalToIpcY(cModule *ipcX, cModule *ipcY)
Definition: DA.cc:111
const Address * resolveApnToBestAddress(const APN &apn)
Definition: DA.cc:31
Distributed Application Process name a.k.a. DAP class.
Definition: DAP.h:34
DirectoryEntry * resolveApn(const APN &apn)
Definition: DA.cc:187