~ubuntu-branches/ubuntu/trusty/ibsim/trusty

« back to all changes in this revision

Viewing changes to ibsim/sim.h

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2009-10-21 19:36:00 UTC
  • Revision ID: james.westby@ubuntu.com-20091021193600-nn3g67dgfqcasag2
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
 
3
 *
 
4
 * This file is part of ibsim.
 
5
 *
 
6
 * ibsim is available to you under a choice of one of two licenses.
 
7
 * You may choose to be licensed under the terms of the GNU
 
8
 * General Public License (GPL) Version 2, available from the file
 
9
 * COPYING in the main directory of this source tree, or the
 
10
 * OpenIB.org BSD license below:
 
11
 *
 
12
 *     Redistribution and use in source and binary forms, with or
 
13
 *     without modification, are permitted provided that the following
 
14
 *     conditions are met:
 
15
 *
 
16
 *      - Redistributions of source code must retain the above
 
17
 *        copyright notice, this list of conditions and the following
 
18
 *        disclaimer.
 
19
 *
 
20
 *      - Redistributions in binary form must reproduce the above
 
21
 *        copyright notice, this list of conditions and the following
 
22
 *        disclaimer in the documentation and/or other materials
 
23
 *        provided with the distribution.
 
24
 *
 
25
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
26
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
27
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
28
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
29
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
30
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
31
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
32
 * SOFTWARE.
 
33
 */
 
34
 
 
35
#ifndef __SIM_H__
 
36
#define __SIM_H__
 
37
 
 
38
#include <infiniband/common.h>
 
39
#include <infiniband/mad.h>
 
40
 
 
41
#define MAXNETNODES     2048
 
42
#define MAXNETSWITCHS   256
 
43
#define MAXNETPORTS     (MAXNETSWITCHS*36+MAXNETNODES*2)
 
44
#define MAXNETALIASES   MAXNETPORTS
 
45
 
 
46
#define MAXLINEARCAP    (30*1024)
 
47
#define MAXMCASTCAP     1024
 
48
#define LASTBLOCK32     (MAXMCASTCAP/32-1)
 
49
// NUMBEROFPORTMASK means that 32port switches could only be build
 
50
#define NUMBEROFPORTMASK 2
 
51
#define LASTPORTMASK    (NUMBEROFPORTMASK-1)
 
52
// linkwidth == 4X - must be one width only 1,2 or 8
 
53
#define LINKWIDTH_1x        1
 
54
#define LINKWIDTH_4x        2
 
55
#define LINKWIDTH_8x        4
 
56
#define LINKWIDTH_12x       8
 
57
#define LINKWIDTH_1x_4x     3
 
58
#define LINKWIDTH_1x_4x_12x 11
 
59
 
 
60
#define LINKSPEED_SDR       1
 
61
#define LINKSPEED_DDR       2
 
62
#define LINKSPEED_QDR       4
 
63
#define LINKSPEED_SDR_DDR   3
 
64
 
 
65
#define DEFAULT_LINKWIDTH       LINKWIDTH_4x
 
66
#define DEFAULT_LINKSPEED       LINKSPEED_SDR
 
67
 
 
68
#define NODEPREFIX      20
 
69
#define NODEIDLEN       65
 
70
#define ALIASLEN        40
 
71
 
 
72
#define MAXHOPS 16
 
73
 
 
74
enum NODE_TYPES {
 
75
        NO_NODE = 0,
 
76
        HCA_NODE,
 
77
        SWITCH_NODE,
 
78
        ROUTER_NODE,
 
79
 
 
80
        NODE_TYPES
 
81
};
 
82
 
 
83
enum TRAP_TYPE_ID {
 
84
        TRAP_128,
 
85
        TRAP_144,
 
86
 
 
87
        TRAP_NUM_LAST
 
88
};
 
89
 
 
90
/* some PortInfo capmask fields */
 
91
enum PORTINFO_CAPMASK {
 
92
        CAPMASK_ISSM = (1<<1),
 
93
        CAPMASK_ISNOTICE = (1<<2),
 
94
        CAPMASK_ISTRAP = (1<<3),
 
95
        CAPMASK_ISCAPMASKTRAP = (1<<22),
 
96
};
 
97
 
 
98
enum GS_PERF_COUNTER_SELECT_MASK {
 
99
        GS_PERF_ERR_SYM_MASK = (1UL << 0),      // SYMBOL_ERROR_COUNTER
 
100
        GS_PERF_LINK_RECOVERS_MASK = (1UL << 1),        // LINK_ERROR_RECOVERY_COUNTER
 
101
        GS_PERF_LINK_DOWNED_MASK = (1UL << 2),  // LINK_DOWNED_COUNTER
 
102
        GS_PERF_ERR_RCV_MASK = (1UL << 3),      // PORT_RCV_ERRORS
 
103
        GS_PERF_ERR_PHYSRCV_MASK = (1UL << 4),  // PORT_RCV_REMOTE_PHYSICAL_ERRORS
 
104
        GS_PERF_ERR_SWITCH_REL_MASK = (1UL << 5),       // PORT_RCV_SWITCH_RELAY_ERRORS
 
105
        GS_PERF_XMT_DISCARDS_MASK = (1UL << 6), // PORT_XMIT_DISCARDS
 
106
        GS_PERF_ERR_XMTCONSTR_MASK = (1UL << 7),        // PORT_XMIT_CONSTRAINT_ERRORS
 
107
        GS_PERF_ERR_RCVCONSTR_MASK = (1UL << 8),        // PORT_RCV_CONSTRAINT_ERRORS
 
108
        GS_PERF_ERR_LOCALINTEG_MASK = (1UL << 9),       // LOCAL_LINK_INTEGRITY_ERRORS
 
109
        GS_PERF_ERR_EXCESS_OVR_MASK = (1UL << 10),      // EXCESSIVE_BUFFER_OVERRUN_ERRORS
 
110
        GS_PERF_VL15_DROPPED_MASK = (1UL << 11),
 
111
        GS_PERF_XMT_BYTES_MASK = (1UL << 12),   // PORT_XMIT_DATA
 
112
        GS_PERF_RCV_BYTES_MASK = (1UL << 13),   // PORT_RCV_DATA
 
113
        GS_PERF_XMT_PKTS_MASK = (1UL << 14),    // PORT_XMIT_PKTS
 
114
        GS_PERF_RCV_PKTS_MASK = (1UL << 15),    // PORT_RCV_PKTS
 
115
};
 
116
 
 
117
enum GS_PC_EXT_SELECT_MASK {
 
118
        GS_PC_EXT_XMIT_DATA = 1 << 0,
 
119
        GS_PC_EXT_RECV_DATA = 1 << 1,
 
120
        GS_PC_EXT_XMIT_PKTS = 1 << 2,
 
121
        GS_PC_EXT_RECV_PKTS = 1 << 3,
 
122
        GS_PC_EXT_UCAST_XMIT = 1 << 4,
 
123
        GS_PC_EXT_UCAST_RECV = 1 << 5,
 
124
        GS_PC_EXT_MCAST_XMIT = 1 << 6,
 
125
        GS_PC_EXT_MCAST_RECV = 1 << 7,
 
126
};
 
127
 
 
128
enum GS_PERF_COUNTER_SELECT_LIMIT {
 
129
        GS_PERF_ERR_SYM_LIMIT = 0xffff,
 
130
        GS_PERF_LINK_RECOVERS_LIMIT = 0xff,
 
131
        GS_PERF_LINK_DOWNED_LIMIT = 0xff,
 
132
        GS_PERF_ERR_RCV_LIMIT = 0xffff,
 
133
        GS_PERF_ERR_PHYSRCV_LIMIT = 0xffff,
 
134
        GS_PERF_ERR_SWITCH_REL_LIMIT = 0xffff,
 
135
        GS_PERF_XMT_DISCARDS_LIMIT = 0xffff,
 
136
        GS_PERF_ERR_XMTCONSTR_LIMIT = 0xff,
 
137
        GS_PERF_ERR_RCVCONSTR_LIMIT = 0xff,
 
138
        GS_PERF_ERR_LOCALINTEG_LIMIT = 0xf,
 
139
        GS_PERF_ERR_EXCESS_OVR_LIMIT = 0xf,
 
140
        GS_PERF_VL15_DROPPED_LIMIT = 0xffff,
 
141
        GS_PERF_XMT_BYTES_LIMIT = 0xffffffff,
 
142
        GS_PERF_RCV_BYTES_LIMIT = 0xffffffff,
 
143
        GS_PERF_XMT_PKTS_LIMIT = 0xffffffff,
 
144
        GS_PERF_RCV_PKTS_LIMIT = 0xffffffff,
 
145
};
 
146
 
 
147
typedef struct Port Port;
 
148
typedef struct Portinfo Portinfo;
 
149
typedef struct Switch Switch;
 
150
typedef struct Nodeinfo Nodeinfo;
 
151
typedef struct Node Node;
 
152
typedef struct Client Client;
 
153
typedef struct Portcounters Portcounters;
 
154
 
 
155
struct Portinfo {
 
156
        int localport;
 
157
        int linkwidthen;
 
158
        int linkspeeden;
 
159
};
 
160
 
 
161
struct Portcounters {
 
162
        uint64_t ext_xmit_data;
 
163
        uint64_t ext_recv_data;
 
164
        uint64_t ext_xmit_pkts;
 
165
        uint64_t ext_recv_pkts;
 
166
        uint64_t ext_ucast_xmit;
 
167
        uint64_t ext_ucast_recv;
 
168
        uint64_t ext_mcast_xmit;
 
169
        uint64_t ext_mcast_recv;
 
170
        uint32_t flow_xmt_pkts;
 
171
        uint32_t flow_xmt_bytes;
 
172
        uint32_t flow_rcv_pkts;
 
173
        uint32_t flow_rcv_bytes;
 
174
        uint16_t xmitdiscards;
 
175
        uint16_t vl15dropped;
 
176
        uint16_t linkrecovers;
 
177
        uint8_t linkdowned;
 
178
        uint16_t errs_rcv;
 
179
        uint16_t errs_sym;
 
180
        uint8_t errs_localinteg;
 
181
        uint16_t errs_remphysrcv;
 
182
        uint8_t errs_xmtconstraint;
 
183
        uint8_t errs_rcvconstraint;
 
184
        uint16_t errs_rcvswitchrelay;
 
185
        uint8_t errs_excessbufovrrun;
 
186
};
 
187
 
 
188
struct Port {
 
189
        uint64_t portguid;
 
190
        int portnum;
 
191
        int lid;
 
192
        int smlid;
 
193
        int linkwidth;
 
194
        int linkwidthena;
 
195
        int linkspeed;
 
196
        int linkspeedena;
 
197
        int state;
 
198
        int physstate;
 
199
        int lmc;
 
200
        int hoqlife;
 
201
        uint8_t op_vls;
 
202
        uint8_t portinfo[64];
 
203
 
 
204
        char remotenodeid[NODEIDLEN];
 
205
        char remotealias[ALIASLEN + 1];
 
206
        char alias[ALIASLEN + 1];
 
207
        Node *remotenode;
 
208
        int remoteport;
 
209
        Node *previous_remotenode;
 
210
        int previous_remoteport;
 
211
        int errrate;
 
212
        uint16_t errattr;
 
213
        Node *node;
 
214
        Portcounters portcounters;
 
215
        uint16_t *pkey_tbl;
 
216
        uint8_t *sl2vl;
 
217
        struct vlarb {
 
218
                uint8_t vl;
 
219
                uint8_t weight;
 
220
        } vlarb_high[64], vlarb_low[64];
 
221
};
 
222
 
 
223
struct Switch {
 
224
        int linearcap;
 
225
//      int randomcap;
 
226
        int multicastcap;
 
227
        int linearFDBtop;
 
228
        int portchange;
 
229
        int lifetime;
 
230
        uint8_t switchinfo[64];
 
231
        Node *node;
 
232
        uint8_t *fdb;
 
233
        uint8_t *mfdb;
 
234
};
 
235
 
 
236
struct Node {
 
237
        int type;
 
238
        int numports;
 
239
        uint64_t sysguid;
 
240
        uint64_t nodeguid;      // also portguid
 
241
        int portsbase;          // in port table
 
242
        char nodeid[NODEIDLEN]; // contain nodeid[NODEIDLEN]
 
243
        uint8_t nodeinfo[64];
 
244
        char nodedesc[64];
 
245
        Switch *sw;
 
246
        Client *clist;          // client list
 
247
};
 
248
 
 
249
struct Nodeinfo {
 
250
        int localport;
 
251
};
 
252
 
 
253
struct Client {
 
254
        int id;
 
255
        int pid;
 
256
        Port *port;
 
257
        int qp;
 
258
        int issm;
 
259
        int fd;
 
260
};
 
261
 
 
262
// ibsim.c
 
263
int list_connections(FILE * out);
 
264
Client *find_client(Port * port, int response, int qp, uint64_t trid);
 
265
int disconnect_client(int id);
 
266
 
 
267
// sim_net.c
 
268
Node *find_node(char *desc);
 
269
Node *find_node_by_desc(char *desc);
 
270
Node *find_node_by_guid(uint64_t guid);
 
271
const char *node_type_name(unsigned type);
 
272
Port *node_get_port(Node * node, int portnum);
 
273
void reset_port(Port * port);
 
274
int link_ports(Port * lport, Port * rport);
 
275
void update_portinfo(Port * p);
 
276
int build_net(char *netconf);
 
277
int connect_ports(void);
 
278
char *expand_name(char *base, char *name, char **portstr);
 
279
int read_netconf(char *name, FILE * out);
 
280
int set_default_port(char *nodeid);
 
281
int readline(int fd, char *buf, int sz);
 
282
 
 
283
// sim_cmd.c
 
284
int do_cmd(char *buf, FILE *f);
 
285
int sim_cmd_file(FILE * file, char *line);
 
286
void *sim_cmd_thread(void *file);
 
287
 
 
288
// sim_mad.c
 
289
int process_packet(Client * cl, void *p, int size, Client ** dcl);
 
290
int send_trap(Port * port, int trapnum);
 
291
 
 
292
extern Port *default_port;
 
293
extern int simverb, modified;
 
294
extern int netstarted;
 
295
 
 
296
#endif                          /* __SIM_H__ */