2
* Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
4
* This software is available to you under a choice of one of two
5
* licenses. You may choose to be licensed under the terms of the GNU
6
* General Public License (GPL) Version 2, available from the file
7
* COPYING in the main directory of this source tree, or the
8
* OpenIB.org BSD license below:
10
* Redistribution and use in source and binary forms, with or
11
* without modification, are permitted provided that the following
14
* - Redistributions of source code must retain the above
15
* copyright notice, this list of conditions and the following
18
* - Redistributions in binary form must reproduce the above
19
* copyright notice, this list of conditions and the following
20
* disclaimer in the documentation and/or other materials
21
* provided with the distribution.
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
#include "git_version.h"
44
//////////////////////////////////////////////////////////////
49
char *IBMgtSim::getSimulatorDir()
51
static char *ibmgtSimDir = NULL;
52
static char *defaultIbmgtSimDir = "/tmp/ibmgtsim";
54
if (ibmgtSimDir == NULL)
56
ibmgtSimDir = getenv("IBMGTSIM_DIR");
57
if (ibmgtSimDir == NULL) {
58
printf("-W- Environment variable: IBMGTSIM_DIR does not exist.\n");
59
printf(" Please create one used by the simulator.\n");
60
printf(" Using /tmp/ibmgtsim as default.\n");
61
ibmgtSimDir = defaultIbmgtSimDir;
67
/* allocate guids to the nodes */
69
IBMgtSim::allocateFabricNodeGuids()
73
MSGREG(errMsg1, 'F', "Fail to open guid dump file:$", "server");
74
string dumpFileName(getSimulatorDir());
75
dumpFileName += "/ibmgtsim.guids.txt";
76
dumpFile = fopen(dumpFileName.c_str(), "w");
79
MSGSND(errMsg1, dumpFileName);
83
MSGREG(msg1, 'I', "Assigning Guids ...", "server");
86
uint64_t curGuid = 0x0002c90000000000ULL;
88
/* simply go over all nodes and allocate guids */
89
for (map_str_pnode::iterator nI = pFabric->NodeByName.begin();
90
nI != pFabric->NodeByName.end();
93
IBNode *pNode = (*nI).second;
94
pNode->guid_set(++curGuid);
95
fprintf(dumpFile, "NODE %s 0x%016" PRIx64 "\n",
96
pNode->name.c_str(), pNode->guid_get());
98
/* go over all ports of the node and assign guid */
99
for (unsigned int pn = 1; pn <= pNode->numPorts; pn++)
101
IBPort *pPort = pNode->getPort(pn);
102
if (! pPort) continue;
104
if (pNode->type == IB_SW_NODE)
105
pPort->guid_set(curGuid);
108
pPort->guid_set(++curGuid);
109
fprintf(dumpFile, "PORT %s 0x%016" PRIx64 "\n",
110
pPort->getName().c_str(), pPort->guid_get());
115
/* assign system guids by first one */
116
IBSystem *pSystem = pNode->p_system;
117
if (pSystem && (pSystem->guid_get() == 0))
119
pSystem->guid_set(++curGuid);
120
fprintf(dumpFile, "SYSTEM %s 0x%016" PRIx64 "\n",
121
pSystem->name.c_str(), pSystem->guid_get());
130
/* initialize simulator nodes */
131
int IBMgtSim::populateFabricNodes()
134
MSGREG(msg1, 'I', "Populating Fabric Nodes ...", "server");
137
/* simply go over all nodes and instantiate the sim node */
138
for (map_str_pnode::iterator nI = pFabric->NodeByName.begin();
139
nI != pFabric->NodeByName.end();
142
IBNode *pNode = (*nI).second;
143
IBMSNode *pSimNode = new IBMSNode(this, pNode);
144
ibmsSetIBNodeSimNode(pNode, pSimNode);
146
list_uint16 smClassList;
147
smClassList.push_back(0x1);
148
smClassList.push_back(0x81);
149
IBMSSma *pSma = new IBMSSma(pSimNode, smClassList);
152
MSGREG(err1, 'F', "Fail to allocate SMA for Node:$", "server");
153
MSGSND(err1, pNode->name);
157
list_uint16 vsClassList;
158
vsClassList.push_back(0x9);
159
vsClassList.push_back(0x10);
160
IBMSVendorSpecific *pVsa = new IBMSVendorSpecific(pSimNode, vsClassList);
163
MSGREG(err2, 'F', "Fail to allocate VSA for Node:$", "server");
164
MSGSND(err2, pNode->name);
168
IBMSPma *pPma = new IBMSPma(pSimNode, 0x04);
171
MSGREG(err3, 'F', "Fail to allocate PMA for Node:$", "server");
172
MSGSND(err3, pNode->name);
180
/* Initialize the fabric server and dispatcher */
181
int IBMgtSim::init(string topoFileName, int serverPortNum, int numWorkers)
183
/* parse the given fabric */
184
pFabric = new IBFabric;
186
if (pFabric->parseTopology(topoFileName)) {
187
cout << "-E- Fail to parse topology file:" << topoFileName << endl;
191
/* allocate guids to the nodes */
192
allocateFabricNodeGuids();
194
/* initialize simulator nodes */
195
populateFabricNodes();
197
/* try to generate the server on the given port or next ones... */
200
pServer = new IBMSServer(this, serverPortNum++);
202
if (pServer->isAlive())
207
} while (trys++ < 10);
209
if (!pServer->isAlive())
212
pDispatcher = new IBMSDispatcher(numWorkers, 50, 10);
217
//////////////////////////////////////////////////////////////
219
static char IBMgtSimUsage[] =
220
"Usage: ibmgtsim [-vh] -t <topology file> [-p <server port>][-w <num workers>]";
224
cout << IBMgtSimUsage << endl;
229
cout << "HELP" << endl;
232
#ifndef IBMGTSIM_CODE_VERSION
233
#define IBMGTSIM_CODE_VERSION "undefined"
235
const char * ibmsSourceVersion = IBMGTSIM_CODE_VERSION ;
237
//////////////////////////////////////////////////////////////
242
#ifdef BUILD_STANDALONE_SIM
243
int main(int argc, char **argv)
246
* Parsing of Command Line
249
string TopoFile = string("");
251
int serverPortNum = 42561;
252
int verbosity = MsgDefault;
255
const char * const short_option = "vht:w:p:";
257
In the array below, the 2nd parameter specified the number
258
of arguments as follows:
263
const option long_option[] =
265
{ "verbose", 0, NULL, 'v'},
266
{ "help", 0, NULL, 'h'},
267
{ "port-num", 1, NULL, 'p'},
268
{ "workers", 1, NULL, 'w'},
269
{ "topology", 1, NULL, 't'},
270
{ NULL, 0, NULL, 0 } /* Required at the end of the array */
273
printf("-----------------------------------------------------\n\n");
274
printf(" Mellanox Technologies IB Management Simulator\n");
275
printf(" -----------------------------------------------\n\n");
279
next_option = getopt_long(argc, argv, short_option, long_option, NULL);
286
verbosity = MsgShowAll;
287
printf(" Verbose Mode\n");
294
serverPortNum = atoi(optarg);
295
printf(" Using Port:%u\n", serverPortNum);
300
Specifies number of worker threads
302
numWorkers = atoi(optarg);
303
printf(" Initializing %u mad dispatcher threads.\n", numWorkers);
308
Specifies Subnet Cabling file
310
TopoFile = string(optarg);
311
printf(" Using topology file:%s.\n", TopoFile.c_str());
320
break; /* done with option */
321
default: /* something wrong */
326
while(next_option != -1);
328
if (!TopoFile.size()) {
329
printf("-E- Missing some mandatory arguments.\n");
334
/* initialize the logger */
335
msgMgr(verbosity, &cout);
339
sim.init(TopoFile, serverPortNum, numWorkers);