File: con_000.cpp

package info (click to toggle)
openhpi 2.12.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,580 kB
  • ctags: 13,105
  • sloc: ansic: 177,276; cpp: 31,164; sh: 9,315; makefile: 4,463; perl: 1,529
file content (239 lines) | stat: -rw-r--r-- 4,983 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * Stress test for the connection layer
 *
 * Copyright (c) 2004 by FORCE Computers
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
 * file and program are licensed under a BSD style license.  See
 * the Copying file included with the OpenHPI distribution for
 * full licensing terms.
 *
 * Authors:
 *     Thomas Kanngieser <thomas.kanngieser@fci.com>
 *
 * This test requires:
 * - IPMI hardware with RMCP
 * - RMCP configuration like IP address, port, user, password
 * 
 * So it is not enabled by default.
 */

#include <stdio.h>
#include "ipmi_con_lan.h"
#include <netdb.h>
#include <string.h>


#define dNumThreads 30
#define dNumCmdsPerThread 100

static const char    *host   = "192.168.110.187";
static int            port   = 623;
static const char    *user   = "kanne";
static const char    *passwd = "kanne";
static tIpmiAuthType  auth   = eIpmiAuthTypeNone;
static tIpmiPrivilege priv   = eIpmiPrivilegeAdmin;
static cIpmiConLan   *con  = 0;

static int num_threads = 0;
static int num_cmds = 0;

cThreadLockRw lock;


class cThreadTest : public cThread
{
  int m_id;
  cIpmiAddr m_addr;

public:
  cThreadTest( int id, unsigned char slave_addr )
    : m_id( id ), m_addr( eIpmiAddrTypeIpmb, 0, 0, slave_addr )
  {
  }

  int SendCommand( const cIpmiMsg &msg, cIpmiMsg &rsp )
  {
    num_cmds++;

    return con->ExecuteCmd( m_addr, msg, rsp );
  }

  void ClearSel()
  {
    lock.WriteLock();

    // get a reservation
    cIpmiMsg msg( eIpmiNetfnStorage, eIpmiCmdReserveSel );
    msg.m_data_len = 0;

    cIpmiMsg rsp;

    int rv = SendCommand( msg, rsp );

    unsigned short reservation = IpmiGetUint16( rsp.m_data + 1 );

    msg.m_netfn = eIpmiNetfnStorage;
    msg.m_cmd   = eIpmiCmdClearSel;
    IpmiSetUint16( msg.m_data, reservation );
    msg.m_data[2] = 'C';
    msg.m_data[3] = 'L';
    msg.m_data[4] = 'R';
    msg.m_data_len = 6;

    bool first = true;
    int count = 100;

    do
       {
         msg.m_data[5] = first ? 0xaa : 0; // initiate erase/ erase status
         first = false;

         rsp.m_data[0] = 0xff;

         rv = SendCommand( msg, rsp );
       }
    while( (rsp.m_data[1] & 0x7) != 0x1 && count-- > 0 );

    lock.WriteUnlock();
  }

  void Cmd()
  {
    cIpmiMsg  msg( eIpmiNetfnStorage, eIpmiCmdAddSelEntry );
    msg.m_data[0] = 0;
    msg.m_data[1] = 0;
    msg.m_data[2] = 0xc0;
    msg.m_data[3] = 0;
    msg.m_data[4] = 0;
    msg.m_data[5] = 0;
    msg.m_data[6] = 0;
    msg.m_data[7] = 1;
    msg.m_data[8] = 2;
    msg.m_data[9] = 3;
    msg.m_data[10] = 0;
    msg.m_data[11] = 0;
    msg.m_data[12] = 0;
    msg.m_data[13] = 0;
    msg.m_data[14] = 0;
    msg.m_data[15] = 0;
    msg.m_data_len = 16;

    cIpmiMsg rsp;

    lock.ReadLock();

    for( int i = 0; i < 10; i++ )
       {
         int rv = SendCommand( msg, rsp );

         if ( rv || rsp.m_data[0] )
            {
              lock.ReadUnlock();

              ClearSel();

              lock.ReadLock(); 
            }
       }

    lock.ReadUnlock();
  }

  virtual void *Run()
  {
    num_threads++;

    for( int i = 0; i < dNumCmdsPerThread; i++ )
         Cmd();

    num_threads--;

    delete this;

    return 0;
  }
};


class cIpmiConLanTest : public cIpmiConLan
{
public:
  cIpmiConLanTest( unsigned int timeout, 
                     struct in_addr addr, int por,
                     tIpmiAuthType aut, tIpmiPrivilege pri, 
                     char *u, char *p )
    : cIpmiConLan( timeout, 0, addr, por, aut, pri, 
                   u, p )
  {
  }

  virtual ~cIpmiConLanTest()
  {
  }

  virtual void HandleAsyncEvent( const cIpmiAddr & /*addr*/, const cIpmiMsg & /*msg*/ )
  {
  }
};


int
main( int /*argc*/, char * /*argv*/[] )
{
  stdlog.Open( dIpmiLogFile|dIpmiLogStdOut );

  struct hostent *ent = gethostbyname( host );

  if ( !ent )
     {
       stdlog << "unable to resolve IPMI LAN address: " << host << " !\n";
       return 1;
     }

  struct in_addr lan_addr;
  memcpy( &lan_addr, ent->h_addr_list[0], ent->h_length );

  con = new cIpmiConLanTest( 5000,
                             lan_addr, port,
                             auth, priv,
                             const_cast<char *>(user),
                             const_cast<char *>(passwd) );

  con->SetMaxOutstanding( 4 );

  int rv = con->Open() ? 0 : 1;

  if ( !rv )
     {
       time_t t0 = time( 0 );
       
       for( int i = 0; i < dNumThreads; i++ )
          {
            cThreadTest *t = new cThreadTest( i, 0x20 );
            t->Start();
          }

       sleep( 1 );

       while( num_threads )
          {
            sleep( 1 );
            stdlog << "### " << num_cmds << "\n";
          }

       time_t t = time( 0 ) - t0;

       stdlog << "time: " << (int)t << "s\n"; 
     }

  delete con;

  stdlog << num_cmds << " GetDeviceId\n";

  stdlog.Close();

  return rv;
}