-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASControl.h
More file actions
243 lines (210 loc) · 4.92 KB
/
ASControl.h
File metadata and controls
243 lines (210 loc) · 4.92 KB
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
240
241
242
//============================================================================
//
// MODULE NAME: ASControl.h
//
// MODULE DESCRIPTION:
//
//
//
//
// SPECIAL CONSIDERATIONS:
//
//
//****************************************************************************
//
// REVISION HISTORY:
//
// DATE DESIGNER REASON
// -------- ------------ --------------------------------------
// 09/05/2011 JiMeixiang Original
// 06/01/2012 WangXinXin Modified
//
//============================================================================
#ifndef _ASControl_H
#define _ASControl_H
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <errno.h>
#include <sys/ipc.h>
#include <fstream>
#include <netdb.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include "se_thread.h"
#include "Program.H"
#include "AppTable.H"
#include "AppControl.H"
#include "SeAddr.H"
#include "SeMsg.H"
#include "Misc.H"
#include "se_error.h"
#include "SeIntf.H"
#include "CDbInterface.h"//shm interface
#include "Ss7BaseMsg.h"
#include "NnsfCommonDefs.h"
//for ptest_thread added by wangxx 20120827
#include "SeMsg.H"
#include "SeAddr.H"
#include <sys/time.h>
#include <time.h>
#include "ReadCfgFile.h"
#include "writeLogFile.h"
#include "Alarm.h"
//#include "SpRptAlarmReport.hh"
//#include "SpRptSubmission.hh"
/*******视具体情形填写*************/
#define BOARD_ETH ETH2 //板上使用网口
#define CFG_FILE_PATH "/opt/CTIR/etc/config.cfg"
/******************************************/
#define SA struct sockaddr
#define MAXLINE 4096 /* max text line length */
#define P_SVR_PORT 6001//primary(config active)
#define S_SVR_PORT 6002
#define ASHB_HDR 0x0a0b0c0d
#define ACTIVE_BOARD "Active_Board"
#define STANDBY_BOARD "Standby_Board"
#define MAXBUF 1024
#define L_DNAR_ALIVE 0x01
#define DNAR_UPDATE 0x08
#define TO_APP_PORT 5091
#define LOCAL_DFLT_IP "127.0.0.1"
#define SOCK_INADDR_LEN sizeof(struct sockaddr_in)
#define MSU_HDR_SIZE sizeof(S_MSU_HDR)
#define DREVSYNC_CFG_FILE_PATH "/opt/CTIR/etc/DRevSync.cfg"
extern Alarm* g_AlarmObjPtr;
typedef struct
{
int header; // AS_HDR 0x0a0b0c0d
int dIpAdrs; /*destination IP*/
int sIpAdrs; /*source IP*/
int hbSeq;
int invoke;
int board_as;
int dnar_alive;
//char* pData; /*start address of data area.*/
}HB4ASCTRL;
typedef struct
{
int local_as;
char local_ip[32];
char peer_ip[32];
}LOCAL_CFG;
enum hb_type
{
HB_SND = 1,
HB_REPLY,
};
enum {
IP_POS=0,
AS_POS,
};
union ipu{
long ip;
unsigned char ipchar[4];
};
enum eth_sequence
{
//127.0.0.1=0
ETH0=1,
ETH1,
ETH2,
ETH3,
ETH4,
};
enum AS_TYPE//两块 CSP board 主备状态
{
AS_PEND=0,
AS_STANDBY,
AS_ACTIVE,
};
const char AS_str[3][16]={
"AS_PEND",
"AS_STANDBY",
"AS_ACTIVE"
};
typedef struct{
unsigned int duration_seconds;
}S_IGNORE_DNAR;
typedef struct{
unsigned char msgId;
union{
S_IGNORE_DNAR ignore;
}msgbody;
}S_TEST_MSG;
enum MessageId
{
begin,
ignore_dnar,
show_start_time,
end,
};
/*for reporting peer-board linkset-status,add by jimx 20111213,begin*/
typedef struct
{
UINT4 _msgseq;
UINT2 _msgProvId;
UINT2 _destModule;
UINT2 _msgLen;
UINT2 _msgId;
}S_MSU_HDR;
class ASControl
{
public:
static ASControl* instance();
void ignore_func(S_TEST_MSG* Msg);
void SendDnarDeadAlarmResume();
void show_time();
long getlocalhostip(int eth);
char* timeStamp();
int reverseCfg(int config);
int selectTcpPort (int loc_as);
void SHM_updateAS(int as_state);
void SHM_ASControl_init();
void SendDnarDeadAlarm();
void SHM_checkDnarAlive();
void notify_as(int req_as);
void readLocalConfig();
void readDRevSyncConfig();
void init_udp_sock(int &sock_snd, sockaddr_in &s_addr);
void peerBoardDown();
void err_doit(int errnoflag, const char *fmt, va_list ap);
void err_sys(const char *fmt, ...);
void err_quit(const char *fmt, ...);
int Fcntl(int fd, int cmd, int arg);
int Select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
int connect_nonb(int sockfd, const SA *saptr, socklen_t salen, int nsec);
void server_func();
void test_func();
void client_func();
void autorun_register();
LOCAL_CFG getlocalcfg();
void setbasetime(time_t t);
void setstarttime(time_t t);
time_t getstarttime();
void set_dnar_status(int v);
void set_curr_as(int v);
bool get_AlarmType();
private:
ASControl(void);
static ASControl* _instance;
time_t _ignore_dnar_duration;
LOCAL_CFG _localcfg;//from config file
time_t _start_time;
time_t _base_time;
const char* _app_name;//="ASControl_App";
int _dnar_status;
int _curr_as;//当前active/standby
char* _business_string;
AlarmInfo _Info;
CDbInterface* _dbIF;
};
#endif