aboutsummaryrefslogtreecommitdiffstats
path: root/sualibrary/sua/sua_tcb.cpp
blob: b4bb7b816323cef681b511cfb3ce7d872a4cad0a (plain)
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
/***************************************************************************
                          sua_tcb.cpp  -  description
                             -------------------
    begin                : Tue Jan 8 2002
    copyright            : (C) 2002 by Lode Coene
    email                : lode.coene@siemens.atea.be
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
/*
 *  $Id: sua_tcb.cpp,v 1.2 2002/10/24 16:12:06 p82609 Exp $
 *
 * SUA implementation according to SUA draft issue 6.
 *
 * Author(s): Lode Coene
 *            
 *
 * Copyright (C) 2001 by Siemens Atea, Herentals, Belgium.
 *
 * Realized in co-operation between Siemens Atea and 
 * Siemens AG, Munich, Germany.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Contact: gery.verwimp@siemens.atea.be
 *          lode.coene@siemens.atea.be
 *
 * The alternative comment
 * inspiration : Daphne
 * "Listen very carefully, I shall say this only once:"
 * "a TCB, a TCB, my kingdom for a TCB"
 *
 * Purpose: This code-file defines the SUA Transaction Control Block(TCB) pool
 *          functions for(needed for SUA connection oriented):
 *          - initialising a single TCB
 *          - initialising the TCB pool
 *          - allocate a TCB
 *          - get a TCB
 *          - release a TCB
 *          And for the Saved SUA msg queue pool
 *          - add SUA msg to queue
 *          - get sua msg from queue
 *          - release the SUA msg from the queue     
 */

#include "sua_debug.h"
#include "sua_tcb.h"
#include "sua_database.h"
#include "sua_logging.h"
#include "sua.h"

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>

#include <netinet/in_systm.h>
#include <netinet/ip.h>         /* includes <netinet/in.h> also ! */
#include <netinet/ip_icmp.h>
#include <netdb.h>
#include <arpa/inet.h>

using namespace std;

/* sua SCOC tcb pool */ 
tcb_Sua_TCB_arr  tcb_pool;

/* sua temporary message store */
tcb_Sua_msgqueue_pool  msg_store; 

/***********************************************************************/
/* Sua SCOC TCB: initialise TCB element                                */
/***********************************************************************/
void tcb_Sua_TCB_str::init_TCB_elem()
{
  state =  scoc_idle;
  Dest_LR = 0;
  Source_LR = 0;
  User_ref_id = 0;
  sctp_Association_id = 0;
  scoc_tcb_id = 0;
  prcl_class =  class0 ;
  return_option = FALSE;
}

/***********************************************************************/
/* Sua SCOC TCB arr: initialise TCB pool                               */
/***********************************************************************/
void tcb_Sua_TCB_arr::init_TCB_pool()
{
  cout << "Initialising ?? \n";
  last_allocated_tcb = 0;
}


/***********************************************************************/
/* Sua SCOC TCB arr: allocate a TCB                                    */
/***********************************************************************/
tcb_Sua_TCB_str  *tcb_Sua_TCB_arr:: allocate_TCB(unsigned int &local_ref){

  last_allocated_tcb++;
  // allocate the TCB
  tcb_Sua_TCB_str new_tcb;
  new_tcb.init_TCB_elem();
  tcb_sua_pair_str tcb_ref_pair(last_allocated_tcb,new_tcb);
  
  tcb_sua_map_iterator_str p = tcb.insert(tcb_ref_pair);
 
  if (p.second)
    {
      char logstring[100];
      sprintf(logstring, "TCB %d allocated",last_allocated_tcb);
      event_log("sua_tcb.c",logstring);
    }
  else
    {
      char logstring[100];
      sprintf(logstring, "No TCB allocated, damm");
      event_log("sua_tcb.c",logstring);
    } 
 
  local_ref = last_allocated_tcb;
  cout << "tcb local ref = " << local_ref << "\n";
  return(&tcb[last_allocated_tcb]);
}

/***********************************************************************/
/* Sua SCOC TCB arr: get address of TCB                                */
/***********************************************************************/
tcb_Sua_TCB_str  *tcb_Sua_TCB_arr:: get_tcb(unsigned int local_ref) {

  return(&tcb[local_ref]);
}
  
/***********************************************************************/
/* Sua SCOC TCB arr: release the TCB                                   */
/***********************************************************************/
void tcb_Sua_TCB_arr:: release_TCB(unsigned int local_reference){

  int count = tcb.erase(local_reference);
 
  if (count != 0)
    {
      char logstring[100];
      sprintf(logstring, "TCB instances %d of LR %d Released : ",count,local_reference);
      event_log("sua_tcb.c",logstring);
    }
  else
    {
      char logstring[100];
      sprintf(logstring, "TCB instance not released");
      event_log("sua_tcb.c",logstring);
    }
  
}

/***********************************************************************/
/* Sua_msg : save msg                                                  */
/***********************************************************************/
void tcb_Sua_msgqueue_pool:: add_msg( unsigned int       sua_assoc_idx,
				      tcb_Sua_msg_elem   sua_msg
				    )
{
  sua_msg.valid = true;
  msg_store.instance[sua_assoc_idx].push(sua_msg);
}

/***********************************************************************/
/* Sua_msg : get msg                                                   */
/***********************************************************************/
tcb_Sua_msg_elem  tcb_Sua_msgqueue_pool:: get_msg( unsigned int sua_assoc_idx )
{
  tcb_Sua_msg_elem   temp_sua_msg;

  temp_sua_msg.valid = false;
  if ( !msg_store.instance[sua_assoc_idx].empty() )
    {
      return( msg_store.instance[sua_assoc_idx].front());
    }
  else
    {
      
      return(temp_sua_msg);
    }
}

/***********************************************************************/
/* Sua_msg : Delete msg                                                */
/***********************************************************************/
void tcb_Sua_msgqueue_pool:: delete_msg( unsigned int sua_assoc_idx )
{
  if ( !msg_store.instance[sua_assoc_idx].empty() )
    msg_store.instance[sua_assoc_idx].pop();
}

// end of module sua_tcb.c