Child: [65cd22] (diff)

Download this file

DA.cc    193 lines (169 with data), 6.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//
// 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/.
//
#include "DA.h"
//Constants
const char* MOD_DIRECTORY = "directory";
const char* MOD_NAMINFO = "namingInformation";
const char* MOD_NEIGHBORTAB = "neighborTable";
const char* MOD_SEARCHTAB = "searchTable";
Define_Module(DA);
void DA::initPointers() {
//Retrieve pointers to submodules
Dir = ModuleAccess<Directory>(MOD_DIRECTORY).get();
NamInfo = ModuleAccess<NamingInformation>(MOD_NAMINFO).get();
NeighborTab = ModuleAccess<NeighborTable>(MOD_NEIGHBORTAB).get();
SearchTab = ModuleAccess<SearchTable>(MOD_SEARCHTAB).get();
}
void DA::initialize()
{
//Retrieve pointers to submodules
initPointers();
}
/** Check whether any IPC within given DIF name is available on computation system with source IPC
*
* @param difName Given DIF name
* @param ipc Source IPC Process
* @return True if yes, otherwise false
*/
bool DA::isDifLocalToIpc(const std::string difName, cModule* ipc) {
cModule* top = ipc->getParentModule();
for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
cModule *submodp = j();
if (isIpcXLocalToIpcY(submodp, ipc)
&& !opp_strcmp(submodp->par(PAR_DIFNAME), difName.c_str()) //...has a given DIF name
)
return true;
}
return false;
}
/**
* Check whether given IPC X is on the same computation system as IPC Y
* @param ipcX target
* @param ipcY source
* @return True if yes, otherwise false.
*/
bool DA::isIpcXLocalToIpcY(cModule* ipcX, cModule* ipcY) {
//Both of them have same parent module
//...AND both of them are IPC (has IPCAddress parameter)
return ipcX->getParentModule() == ipcY->getParentModule()
&& ipcX->hasPar(PAR_IPCADDR) && ipcX->hasPar(PAR_DIFNAME)
&& ipcY->hasPar(PAR_IPCADDR) && ipcY->hasPar(PAR_DIFNAME);
}
bool DA::isAppLocal(const APN& apn) {
cModule* top = this->getParentModule()->getParentModule();
for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
cModule* submodp = j();
if (submodp->hasPar(PAR_APNAME)
&& !opp_strcmp(submodp->par(PAR_APNAME), apn.getName().c_str())
)
return true;
}
return false;
}
bool DA::isDifLocal(const DAP& difName) {
cModule* top = this->getParentModule()->getParentModule();
for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
cModule* submodp = j();
if (submodp->hasPar(PAR_DIFNAME)
&& !opp_strcmp(submodp->par(PAR_DIFNAME), difName.getName().c_str())
)
return true;
}
return false;
}
bool DA::isIpcLocal(cModule* ipc) {
cModule* top = this->getParentModule()->getParentModule();
for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
cModule* submodp = j();
if (submodp == ipc)
return true;
}
return false;
}
cModule* DA::getDifMember(const DAP& difName) {
cModule* top = this->getParentModule()->getParentModule();
for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
cModule* submodp = j();
if (submodp->hasPar(PAR_DIFNAME)
&& !opp_strcmp(submodp->par(PAR_DIFNAME), difName.getName().c_str())
)
return submodp;
}
return NULL;
}
cModule* DA::findIpc(const Address& addr) {
cModule* top = this->getParentModule()->getParentModule();
for (cModule::SubmoduleIterator j(top); !j.end(); j++) {
cModule *submodp = j();
if (submodp->hasPar(PAR_IPCADDR) && submodp->hasPar(PAR_DIFNAME)) {
Address adr = Address(submodp->par(PAR_IPCADDR), submodp->par(PAR_DIFNAME));
if (adr == addr)
return submodp;
}
}
return NULL;
}
FABase* DA::findFaInsideIpc(cModule* ipc) {
return dynamic_cast<FABase*>(ipc->getSubmodule(MOD_FLOWALLOC)->getSubmodule(MOD_FA));
}
DirectoryEntry* DA::resolveApn(const APN& apn) {
Enter_Method("resolveApn()");
APNList apns = NamInfo->findAllApnNames(apn);
//Return first Directory mapping from APN and all its synonyms
for (ApnCItem it = apns.begin(); it != apns.end(); ++it) {
DirectoryEntry* dre = Dir->findDirEntryByApn(*it);
if (dre)
return dre;
}
return NULL;
}
void DA::handleMessage(cMessage *msg)
{
}
/*
cModule* DA::resolveApnToIpc(const APN& apn) {
Enter_Method("resolveApnToDif()");
DirectoryEntry* dre = Dir->findDirEntryByApn(apn);
return dre ? dre->getIpc() : NULL;
}
FABase* DA::resolveApnToFa(const APN& apn) {
Enter_Method("resolveApnToDifFa()");
DirectoryEntry* dre = Dir->findDirEntryByApn(apn);
return dre ? dre->getFlowAlloc() : NULL;
}
std::string DA::resolveApnToIpcPath(const APN& apn) {
Enter_Method("resolveApnToDifName()");
DirectoryEntry* dre = Dir->findDirEntryByApn(apn);
return dre ? dre->getIpcPath() : NULL;
}
std::string DA::resolveApniToIpcPath(const APNamingInfo& apni) {
Enter_Method("resolveApniToDifName()");
//TODO: Vesely - Complete APNI search
return resolveApnToIpcPath(apni.getApn());
}
cModule* DA::resolveApniToIpc(const APNamingInfo& apni) {
Enter_Method("resolveApniToDif()");
//TODO: Vesely - Complete APNI search
return resolveApnToIpc(apni.getApn());
}
FABase* DA::resolveApniToFa(const APNamingInfo& apni) {
Enter_Method("resolveApniToDifFa()");
//TODO: Vesely - Complete APNI search
return resolveApnToFa(apni.getApn());
}
DirectoryEntry* DA::resolveApni(const APNamingInfo& apni) {
return Dir->findEntryByApni(apni);
}
*/