aboutsummaryrefslogtreecommitdiffstats
path: root/sualibrary/sua/sua_adapt.cpp
blob: 5dcb3969679f773114a08849f5c662e88814b59c (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
220
221
222
/***************************************************************************
                          sua_adapt.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_adapt.cpp,v 1.2 2002/02/15 16:19:46 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 : Katrien
 * "Come on barbie, let's go party"
 *
 * Purpose: This code-file defines the SUA adaptation functions used by  
 *          the SUA application for:
 *          - initialising the SUA layer
 *          - reading the SUA configuration file
 *          - registering a local SUA instance
 *          - Setting up the association with a remote SUA node
 *          - get info on a certain (SUA) association
 *          - terminate a association
 *          - convert Hostname(string) to SUAname(Character array)
 *          - convert SUAname(Character array) to Hostname(Character array)
 */

// sua_adapt.c++
// SCCP user adaptation program

#include "sua_debug.h"
#include "sua_database.h"
#include "sua_file.h"
#include "sua_distribution.h"
#include "sua_logging.h"

#ifdef LINUX
    #include <unistd.h>
#endif

#include <sctp.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;
/* definition of SUA local object and of remote object */
db_Sua_LocalList local_sua;
db_Sua_RemoteList remote_sua;
db_Sua_AssociationList Assoc_sua;
db_Sua_NameList NameDB_sua;
db_Sua_ASList ApplicServ_sua;

/***********************************************************************/
/* sua_initialisation                                                  */
/***********************************************************************/
void sua_initialisation()
{
  int res;
  cout << "Initialising SCTP & SUA\n ";
  res = sctp_initLibrary();
  init_logging_file();  
  local_sua.initialize();
  remote_sua.initialize();
  Assoc_sua.initialize();
  cout << "Finished initialising SUA data\n ";
 
} /* end of sua_initialisation */

/***********************************************************************/
/* sua_read_configuration file                                         */
/***********************************************************************/
unsigned int  sua_read_config_file( char *pConfFile)
{
  unsigned int result = SUA_CFG_NO_ERROR;
  string sua_filename;
  sua_filename = pConfFile;
  result = read_sua_file( sua_filename,
			  local_sua,
			  remote_sua,
			  Assoc_sua,
			  NameDB_sua,
			  ApplicServ_sua
			);
  return(result);
}

/***********************************************************************/
/* sua_registerInstance                                                */
/***********************************************************************/
unsigned int sua_registerInstance ( short              local_ssn,
				    Sua_ULP_CallBacks  ulp_callback
				  )
{
  unsigned int result = SUA_REG_NO_ERROR;
  SCTP_ulp_Callbacks SCTPCallbackFunctions;

  SCTPCallbackFunctions.dataArriveNotif = &sctp_DataArriveNotif;
  SCTPCallbackFunctions.networkStatusChangeNotif = &sctp_NetworkStatusChangeNotif;
  SCTPCallbackFunctions.sendFailureNotif = &sctp_SentFailureNotif;
  SCTPCallbackFunctions.communicationLostNotif = &sctp_CommunicationLostNotif;
  SCTPCallbackFunctions.communicationUpNotif = &sctp_CommunicationUpNotif;
  SCTPCallbackFunctions.communicationErrorNotif = &sctp_CommunicationErrorNotif;
  SCTPCallbackFunctions.restartNotif = &sctp_RestartNotif;
  SCTPCallbackFunctions.shutdownCompleteNotif = &sctp_ShutDownCompleteNotif;

  result = Assoc_sua.register_instance ( SCTPCallbackFunctions,
					 ulp_callback,
					 local_sua
				       );

  return(result);
}


/***********************************************************************/
/* sua_associate                                                       */
/***********************************************************************/
unsigned int sua_associate ( )
{
  unsigned int result = SUA_ASS_NO_ERROR;
  result = Assoc_sua.associate_instance( local_sua,
					 remote_sua
				       );
  return(result);

}


/***********************************************************************/
/* sua_getPath                                                         */
/***********************************************************************/
unsigned int sua_getPath( unsigned int assoc_id,
			  sua_Path_str &pathinfo
			)
{
  unsigned int result = SUA_PATH_NO_ERROR;

  if ( Assoc_sua.instance[assoc_id].Dest.nr_of_addrs > 0)
    {
      /*pathinfo.remote_addr.*/
      pathinfo.remote_addr.pc.ipvx = Assoc_sua.instance[assoc_id].Dest.addrs[0];
      /*pathinfo.remote_addr.pc.ss7 = Assoc_sua.instance[assoc_id].Dest.pc;*/
      pathinfo.remote_addr.ssn = remote_sua.instance[Assoc_sua.instance[assoc_id].remote_sua_id].ssn.ssn;

      pathinfo.ASP_status = Assoc_sua.instance[assoc_id].asp.status;

#ifdef DEBUG
      //cout << "remote ssn = " << pathinfo.remote_addr.ssn << "\n";
      //cout << "remote sua_id = " << Assoc_sua.instance[assoc_id].remote_sua_id << "\n";
#endif
    }
  else
    result = SUA_PATH_NO_DEST_ADDR_PRESENT;
  pathinfo.local_addr.pc.ipvx = Assoc_sua.instance[assoc_id].Source.addrs[0];
  pathinfo.local_addr.pc.ss7 = Assoc_sua.instance[assoc_id].Source.pc;
  pathinfo.local_addr.ssn = local_sua.instance[Assoc_sua.instance[assoc_id].local_sua_id].ssn.ssn;

  return (result);

}

/***********************************************************************/
/* sua_terminate                                                       */
/***********************************************************************/
unsigned int sua_terminate( )
{
  unsigned int result = SUA_TERM_NO_ERROR;

  Assoc_sua.shutdown();
  close_logging_file();

  return (result);

}



// end of module sua_adapt.c++