-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcc_basic.h
250 lines (202 loc) · 5.25 KB
/
cc_basic.h
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
243
244
245
246
247
248
249
/*
* cc_of_msg_action functions.
*
* Author: qiang wang <[email protected]>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef CC_BASIC_H
#define CC_BASIC_H 1
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <malloc.h>
#include <assert.h>
#include <pthread.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include <stdint.h>
#include <signal.h>
#include <limits.h>
#include <float.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include "cc_log.h"
#if 0
#include "cc_init_of.h"
#include "cc_socket.h"
#include "cc_utility.h"
#include "cc_double_link.h"
#include "cc_single_link.h"
#include "cc_hash_table.h"
#include "cc_bool.h"
#include "cc_buffer.h"
#include "cc_bool.h"
#include "cc_byte_order.h"
#endif
#define CC_ERROR -1
#define CC_SUCCESS 0
#define CC_CONN_DOWN 1
#define CC_CONN_TIMEOUT_SEC 0
#define CC_CONN_TIMEOUT_USEC 0
/*used to temperaly to restrict the number \
*of linked switch,to make this project go easy
*/
#define CC_MAX_NUM_SWITCH 3
/*used in cc_thread_pool.c to \
*restrict the number of pthread
*/
#define CC_MAX_THREAD_NUM 3
#define CC_BUFFER_SIZE (1024*sizeof(char))
#define FUNC_NAME __FUNCTION__
#define CC_TIMEOUT_FOR_HELLO 5
#define CC_TIMEOUT_FOR_ECHO_REPLY 5
#define CC_RECV_BUFFER_SIZE (USHRT_MAX+sizeof( struct ofp_packet_in )-2)
#define CC_MAX_SOCKET_BUFF 3*1024*1024
#define CC_MAX_PORT 52
#define CC_XID_MAX_ENTRIES 256
enum sw_state{
CC_CONNECT,
CC_DISCONNECT,
CC_WAIT_HELLO,
CC_WAIT_ECHO_REPLY,
};
struct cc_socket{
struct sockaddr_in cc_addr;
//uint16_t port;
int fd;
};
typedef struct cc_socket cc_socket;
struct xid_entry {
uint32_t xid;
struct timeval tv;
};
typedef struct xid_entry xid_entry;
struct xid_table {
hash_table *xid_hash;
list_element* xid_entry_list;
};
typedef struct xid_table xid_table;
struct port_info{
struct ofp_phy_port port;
int valid;
};
typedef struct port_info port_info;
struct each_sw{
pid_t pid;
uint64_t dpid;//datapath_id come from switch_feature_request/reply
cc_socket cc_socket;
//each_sw *next;
char* profile_path;
uint8_t version;
uint32_t n_buffers;
uint8_t n_tables;
uint32_t actions;
uint32_t capabilities;
//port_info* port_head;
port_info sw_port[CC_MAX_PORT];
};
typedef struct each_sw each_sw;
/**************************************************/
struct ofmsg_buf
{
void* data;
size_t length;
void *user_data;
};
typedef struct ofmsg_buf ofmsg_buf;
struct worker
{
void (*process)(void* arg, void* arg_);
//void *(*process) (void *arg);
void *arg;/*»Øµ÷º¯ÊýµÄ²ÎÊý,recv_ofmsg*/
struct worker *next;
};
typedef struct worker CThread_worker;
struct CThread_pool
{
pthread_mutex_t queue_lock;
pthread_cond_t queue_ready;
CThread_worker *queue_head;
int shutdown;
pthread_t *threadid;
/*add 20130310*/
pthread_attr_t *attr;
/*end of add 20130310*/
int max_thread_num;
int cur_queue_size;
};
typedef struct CThread_pool CThread_pool;
#if 0
struct event_handler{
event_handler_callback read_handler;
event_handler_callback write_handler;
void* read_buf;
void* write_buf;
};
typedef struct event_handler event_handler;
#endif
/*when the switch connect in,we should init the struct sw_info
**parm: send_queue and recv_queue should be init.
**parm: eh (event_handler)
**parm: xid_head should be NULL
**parm:
*/
struct sw_info
{
each_sw cc_switch;
pthreat_t cc_sw_thread[CC_MAX_THREAD_NUM];
//uint64_t datapathid;
CThread_pool* cc_recv_thread_pool;
//CThread_pool cc_send_thread_pool;
sw_state state;
message_queue *send_queue;
message_queue *recv_queue;
/* for xid hsah table
* param: xid_latest should be init to zero
* param: xid_table_ sholud be init by cc_init_xid_table
*/
xid_table* xid_table_;
uint32_t xid_latest;
/*for app func to handle the msg send to app
*param: app_fd is the file description to connect to app server
*param: app_server_ip is the ip address of app server
*param: message to restore the app_msg to send to app server
*/
/*int app_fd;
char* app_server_ip;
message_queue *app_recv_queue;
message_queue *app_send_queue;*/
/*set config*/
uint16_t config_flags; // OFPC_* flags
uint16_t miss_send_len; /* Max bytes of new flow that datapath should
send to the controller. */
}
typedef struct sw_info sw_info;
struct worker_buf{
sw_info* cc_sw_info;
buffer* buf;
};
typedef struct worker_buf worker_buf;
//struct cc_socket listen_socket;
//typedef struct sw_queue cc_sw_queue;
#endif//END of cc_basic.h