~ubuntu-branches/ubuntu/vivid/ibutils/vivid

« back to all changes in this revision

Viewing changes to ibdm/ibdm/SysDef.h

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2010-01-11 22:22:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100111222200-53kum2et5nh13rv3
Tags: upstream-1.2-OFED-1.4.2
ImportĀ upstreamĀ versionĀ 1.2-OFED-1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2004 Mellanox Technologies LTD. All rights reserved.
 
3
 *
 
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:
 
9
 *
 
10
 *     Redistribution and use in source and binary forms, with or
 
11
 *     without modification, are permitted provided that the following
 
12
 *     conditions are met:
 
13
 *
 
14
 *      - Redistributions of source code must retain the above
 
15
 *        copyright notice, this list of conditions and the following
 
16
 *        disclaimer.
 
17
 *
 
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.
 
22
 *
 
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
 
30
 * SOFTWARE.
 
31
 *
 
32
 * $Id$
 
33
 */
 
34
 
 
35
/*
 
36
 * Fabric Utilities Project
 
37
 *
 
38
 * Hierarchical Systems Definition DataModel
 
39
 *
 
40
 */
 
41
 
 
42
#ifndef IBDM_SYSDEF_H
 
43
#define IBDM_SYSDEF_H
 
44
 
 
45
 
 
46
#include "Fabric.h"
 
47
 
 
48
typedef map< string, string, strless > map_str_str;
 
49
typedef map< string, class IBSysInstPort *, strless > map_str_pinstport;
 
50
typedef map< string, class IBSysInst *, strless > map_str_psysinsts;
 
51
typedef map< string, class IBSysPortDef *, strless > map_str_psysportdef;
 
52
typedef map< string, class IBSysDef *, strless > map_str_psysdef;
 
53
typedef list< string > list_str;
 
54
 
 
55
// Ports are only connected to other SysInst at the same level.
 
56
// We track upper level connections only in the IBPortDef object.
 
57
class IBSysInstPort {
 
58
  string               name;         // name of this port
 
59
  string               remInstName;
 
60
  string               remPortName;
 
61
  IBLinkWidth          width;
 
62
  IBLinkSpeed          speed;
 
63
 
 
64
 public:
 
65
  IBSysInstPort(string n, char *toNode, char *toPort, IBLinkWidth w, IBLinkSpeed s) {
 
66
    name = n; remInstName = toNode; remPortName = toPort; width = w; speed = s;
 
67
  };
 
68
 
 
69
  friend class IBSysInst;
 
70
  friend class IBSystemsCollection;
 
71
 
 
72
};
 
73
 
 
74
class IBSysInst {
 
75
  string      name;         // name of this inst
 
76
  map_str_str SubInstMods;  // Modifier to apply to each sub inst by hier name
 
77
  map_str_pinstport InstPorts;  // Any inst to inst connections
 
78
  string      master;       // the master system name (without any modifier)
 
79
  int         nodeNumPorts; // only valid for node types.
 
80
  IBNodeType  nodeType;     // node tyep SW/CA
 
81
  int         isNode;       // if non zero makes this instance a node instance.
 
82
 
 
83
 public:
 
84
  // we use two constructors - one for Node and one for SubSys
 
85
  IBSysInst(string n, string m, int np, IBNodeType t) {
 
86
    name = n; isNode = 1; master = m; nodeNumPorts = np; nodeType = t;
 
87
  };
 
88
 
 
89
  IBSysInst(string n, string m) {
 
90
    name = n; isNode = 0; master = m; nodeNumPorts = 0;
 
91
    nodeType = IB_UNKNOWN_NODE_TYPE;
 
92
  };
 
93
 
 
94
  inline int addPort(IBSysInstPort* p_port) {
 
95
    InstPorts[p_port->name] = p_port;
 
96
    return(0);
 
97
  };
 
98
 
 
99
  inline int addInstMod(char *subInstName, char *instMod) {
 
100
    SubInstMods[subInstName] = instMod;
 
101
    return(0);
 
102
  };
 
103
 
 
104
  inline string getName() { return name; };
 
105
 
 
106
  friend class IBSysDef;
 
107
  friend class IBSystemsCollection;
 
108
};
 
109
 
 
110
class IBSysPortDef {
 
111
  string        name;         // name of this port
 
112
  string        instName;     // instance connected to the port
 
113
  string        instPortName; // inst port name connected to this sysport.
 
114
  IBLinkWidth   width;
 
115
  IBLinkSpeed   speed;
 
116
 public:
 
117
  IBSysPortDef(string n, string i, string p, IBLinkWidth w, IBLinkSpeed s) {
 
118
    name = n; instName = i; instPortName = p; width = w; speed = s;
 
119
  };
 
120
 
 
121
  friend class IBSysDef;
 
122
  friend class IBSystemsCollection;
 
123
};
 
124
 
 
125
class IBSysDef {
 
126
  string               fileName;          // The file the system was defined by
 
127
  map_str_psysinsts    SystemsInstByName; // all sub instances by name
 
128
  map_str_psysportdef  SysPortsDefs;      // all sys ports defs
 
129
 
 
130
  map_str_str     SubInstAtts;  // Map of node attributes by hier node name
 
131
                                // We attach these attributes only after smash
 
132
 
 
133
 public:
 
134
 
 
135
  IBSysDef(string fn) {fileName = fn; };
 
136
 
 
137
  // add sub instance attribute
 
138
  inline void setSubInstAttr(string hierInstName, string attrStr) {
 
139
    map_str_str::iterator iaI = SubInstAtts.find(hierInstName);
 
140
    if (iaI == SubInstAtts.end()) {
 
141
      SubInstAtts[hierInstName] = attrStr;
 
142
    } else {
 
143
      (*iaI).second += "," + attrStr;
 
144
    }
 
145
  };
 
146
 
 
147
  inline int addInst (IBSysInst *p_inst) {
 
148
    SystemsInstByName[p_inst->name] = p_inst;
 
149
    return 0;
 
150
  };
 
151
 
 
152
  inline int addSysPort(IBSysPortDef *p_sysPort) {
 
153
    SysPortsDefs[p_sysPort->name] = p_sysPort;
 
154
    return 0;
 
155
  };
 
156
 
 
157
  string getName() {
 
158
    return fileName;
 
159
  };
 
160
 
 
161
  friend class IBSystemsCollection;
 
162
};
 
163
 
 
164
// we collect all top level systems into this
 
165
class IBSystemsCollection {
 
166
  map_str_psysdef SysDefByName; // Map of sub instances by name
 
167
 public:
 
168
 
 
169
  // Initialize the system collection with all available
 
170
  // ibnl files in the given directory path list.
 
171
  int parseSysDefsFromDirs(list< string > dirs);
 
172
 
 
173
  // Parse a system definition netlist
 
174
  int parseIBSysdef(string fileName);
 
175
 
 
176
  // Add a new system def ..
 
177
  inline int addSysDef(string sname, IBSysDef *p_sysDef) {
 
178
    // TODO - check for doubles...
 
179
    SysDefByName[sname] = p_sysDef;
 
180
    return 0;
 
181
  };
 
182
 
 
183
  // given a system type and optionaly a modifier
 
184
  // look it up
 
185
  inline IBSysDef* getSysDef(string sname) {
 
186
    // The modifier is simply added to the system name
 
187
    map_str_psysdef::iterator sI = SysDefByName.find(sname);
 
188
    if (sI != SysDefByName.end()) {
 
189
      return (*sI).second;
 
190
    }
 
191
    return NULL;
 
192
  };
 
193
 
 
194
  // Given the name and type of the system - build its system by applying any
 
195
  // modifiers by hierarchical instance name.
 
196
  IBSystem *makeSystem(
 
197
    IBFabric *p_fabric, string name, string master, map_str_str mods);
 
198
 
 
199
 private:
 
200
  // build all nodes recursively
 
201
  int
 
202
    makeSysNodes(
 
203
      IBFabric *p_fabric,        // the fabric we belong to
 
204
      IBSystem *p_system,        // the system we build
 
205
      IBSysDef *p_parSysDef,     // the sysdef of the parent
 
206
      string    parHierName,     // the hier name of the parent "" for top
 
207
      map_str_str &mods          // hier name based modifiers list
 
208
      );
 
209
 
 
210
  // Get a system definition for an instance applying any modifiers
 
211
  IBSysDef *
 
212
    getInstSysDef(
 
213
      IBSysDef    *p_sysDef,    // parent system def
 
214
      IBSysInst   *p_inst,      // the instance
 
215
      string       hierInstName,// instance hierarchical name
 
216
      map_str_str &mods         // hier name based modifiers list
 
217
      );
 
218
 
 
219
  // find a system port def gven the instance, port name, hierName and
 
220
  IBSysPortDef *
 
221
    getSysPortDefByInstPortName(
 
222
      IBSysDef     *p_sysDef,     // the system definition the port is on
 
223
      IBSysInst    *p_inst,       // the instance
 
224
      string        instPortName, // the port name
 
225
      string        hierInstName, // the hier name of the instance
 
226
      map_str_str  &mods          // hier name based modifiers list
 
227
      );
 
228
 
 
229
  IBPort *
 
230
    makeNodePortByInstAndPortName(
 
231
      IBSystem     *p_system,    // the system we build the node port in
 
232
      IBSysDef     *p_sysDef,     // the system definition holding the inst
 
233
      IBSysInst    *p_inst,       // the instance
 
234
      string        instPortName, // the port name
 
235
      string        hierInstName, // the hier name of the instance
 
236
      map_str_str  &mods          // hier name based modifiers list
 
237
      );
 
238
 
 
239
  // find the lowest point connection of this port and make it if a node port
 
240
  // assumes the nodes were already created for the
 
241
  IBPort *
 
242
    makeNodePortBySysPortDef(
 
243
      IBSystem      *p_system,    // the system we build the node port in
 
244
      IBSysDef      *p_sysDef,    // the system definition the port is on
 
245
      IBSysPortDef  *p_sysPortDef,// system port definition
 
246
      string         parHierName, // the hier name of the parent "" for top
 
247
      map_str_str   &mods         // hier name based modifiers list
 
248
      );
 
249
 
 
250
  // find the lowest point connection of this sub sysport and make a node port
 
251
  // assumes the nodes were already created for the
 
252
  IBPort *
 
253
    makeNodePortBySubSysInstPortName(
 
254
      IBSystem      *p_system,    // the system we build the node port in
 
255
      IBSysDef      *p_sysDef,    // the system definition the inst is in
 
256
      string         instName,    // Name of the instance
 
257
      string         instPortName,// Name of instance port
 
258
      string         parHierName, // the hier name of the parent "" for top
 
259
      map_str_str   &mods         // hier name based modifiers list
 
260
      );
 
261
 
 
262
  //  DFS from top on each level connect all connected SysInst ports
 
263
  int
 
264
    makeSubSystemToSubSystemConns(
 
265
      IBSystem      *p_system,    // the system we build the node port in
 
266
      IBSysDef      *p_sysDef,    // the system definition the port is on
 
267
      string         parHierName, // the hier name of the parent "" for top
 
268
      map_str_str   &mods         // hier name based modifiers list
 
269
      );
 
270
 
 
271
  // dump out names of all defined systems
 
272
  void dump();
 
273
};
 
274
 
 
275
// we use a singleton system repository
 
276
IBSystemsCollection *theSysDefsCollection();
 
277
 
 
278
#endif // IBDM_SYSDEF_H