Switch to unified view

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