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
36
* Fabric Utilities Project
38
* Hierarchical Systems Definition DataModel
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;
55
// Ports are only connected to other SysInst at the same level.
56
// We track upper level connections only in the IBPortDef object.
58
string name; // name of this port
65
IBSysInstPort(string n, char *toNode, char *toPort, IBLinkWidth w, IBLinkSpeed s) {
66
name = n; remInstName = toNode; remPortName = toPort; width = w; speed = s;
69
friend class IBSysInst;
70
friend class IBSystemsCollection;
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.
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;
89
IBSysInst(string n, string m) {
90
name = n; isNode = 0; master = m; nodeNumPorts = 0;
91
nodeType = IB_UNKNOWN_NODE_TYPE;
94
inline int addPort(IBSysInstPort* p_port) {
95
InstPorts[p_port->name] = p_port;
99
inline int addInstMod(char *subInstName, char *instMod) {
100
SubInstMods[subInstName] = instMod;
104
inline string getName() { return name; };
106
friend class IBSysDef;
107
friend class IBSystemsCollection;
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.
117
IBSysPortDef(string n, string i, string p, IBLinkWidth w, IBLinkSpeed s) {
118
name = n; instName = i; instPortName = p; width = w; speed = s;
121
friend class IBSysDef;
122
friend class IBSystemsCollection;
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
130
map_str_str SubInstAtts; // Map of node attributes by hier node name
131
// We attach these attributes only after smash
135
IBSysDef(string fn) {fileName = fn; };
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;
143
(*iaI).second += "," + attrStr;
147
inline int addInst (IBSysInst *p_inst) {
148
SystemsInstByName[p_inst->name] = p_inst;
152
inline int addSysPort(IBSysPortDef *p_sysPort) {
153
SysPortsDefs[p_sysPort->name] = p_sysPort;
161
friend class IBSystemsCollection;
164
// we collect all top level systems into this
165
class IBSystemsCollection {
166
map_str_psysdef SysDefByName; // Map of sub instances by name
169
// Initialize the system collection with all available
170
// ibnl files in the given directory path list.
171
int parseSysDefsFromDirs(list< string > dirs);
173
// Parse a system definition netlist
174
int parseIBSysdef(string fileName);
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;
183
// given a system type and optionaly a modifier
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()) {
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);
200
// build all nodes recursively
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
210
// Get a system definition for an instance applying any modifiers
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
219
// find a system port def gven the instance, port name, hierName and
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
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
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
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
250
// find the lowest point connection of this sub sysport and make a node port
251
// assumes the nodes were already created for the
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
262
// DFS from top on each level connect all connected SysInst ports
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
271
// dump out names of all defined systems
275
// we use a singleton system repository
276
IBSystemsCollection *theSysDefsCollection();
278
#endif // IBDM_SYSDEF_H