sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2001 - 2003
|
sl@0
|
3 |
* NetGroup, Politecnico di Torino (Italy)
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
7 |
* modification, are permitted provided that the following conditions
|
sl@0
|
8 |
* are met:
|
sl@0
|
9 |
*
|
sl@0
|
10 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
11 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
12 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
13 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
14 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
15 |
* 3. Neither the name of the Politecnico di Torino nor the names of its
|
sl@0
|
16 |
* contributors may be used to endorse or promote products derived from
|
sl@0
|
17 |
* this software without specific prior written permission.
|
sl@0
|
18 |
*
|
sl@0
|
19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
sl@0
|
20 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
sl@0
|
21 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
sl@0
|
22 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
sl@0
|
23 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
24 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
sl@0
|
25 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
sl@0
|
26 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
sl@0
|
27 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
sl@0
|
28 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
sl@0
|
29 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
30 |
*
|
sl@0
|
31 |
*/
|
sl@0
|
32 |
|
sl@0
|
33 |
#ifndef __tme_include_
|
sl@0
|
34 |
#define __tme_include_
|
sl@0
|
35 |
|
sl@0
|
36 |
#ifdef WIN_NT_DRIVER
|
sl@0
|
37 |
#include "ndis.h"
|
sl@0
|
38 |
#else
|
sl@0
|
39 |
#include <windows.h>
|
sl@0
|
40 |
#endif /*WIN_NT_DRIVER*/
|
sl@0
|
41 |
|
sl@0
|
42 |
#include "memory_t.h"
|
sl@0
|
43 |
#include "time_calls.h"
|
sl@0
|
44 |
|
sl@0
|
45 |
|
sl@0
|
46 |
/* error codes */
|
sl@0
|
47 |
#define TME_ERROR 0
|
sl@0
|
48 |
#define TME_SUCCESS 1
|
sl@0
|
49 |
#define TME_TRUE 2
|
sl@0
|
50 |
#define TME_FALSE 3
|
sl@0
|
51 |
|
sl@0
|
52 |
/* some constants */
|
sl@0
|
53 |
#define DEFAULT_MEM_EX_SIZE 65536
|
sl@0
|
54 |
#define MAX_TME_DATA_BLOCKS 4
|
sl@0
|
55 |
#define TME_NONE_ACTIVE 0xffffffff
|
sl@0
|
56 |
#define DELTA_READ 2 /* secs */
|
sl@0
|
57 |
|
sl@0
|
58 |
#define TME_LUT_ENTRIES 0x00000000
|
sl@0
|
59 |
#define TME_MAX_FILL_STATE 0x00000001 /*potrebbe servire per un thread a passive level!?!?! */
|
sl@0
|
60 |
#define TME_REHASHING_VALUE 0x00000002
|
sl@0
|
61 |
#define TME_KEY_LEN 0x00000003
|
sl@0
|
62 |
#define TME_SHARED_MEMORY_BLOCKS 0x00000004
|
sl@0
|
63 |
#define TME_FILLED_ENTRIES 0x00000005
|
sl@0
|
64 |
#define TME_BLOCK_SIZE 0x00000006
|
sl@0
|
65 |
#define TME_EXTRA_SEGMENT_SIZE 0x00000007
|
sl@0
|
66 |
#define TME_LOOKUP_CODE 0x00000008
|
sl@0
|
67 |
#define TME_OUT_LUT_EXEC 0x00000009
|
sl@0
|
68 |
#define TME_FILLED_BLOCKS 0x0000000a
|
sl@0
|
69 |
#define TME_DEFAULT_EXEC 0x0000000b
|
sl@0
|
70 |
#define TME_LUT_BASE_ADDRESS 0x0000000c
|
sl@0
|
71 |
#define TME_SHARED_MEMORY_BASE_ADDRESS 0x0000000d
|
sl@0
|
72 |
#define TME_EXTRA_SEGMENT_BASE_ADDRESS 0x0000000e
|
sl@0
|
73 |
#define TME_LAST_FOUND 0x0000000f /* contains the offset of the last found entry */
|
sl@0
|
74 |
#define TME_LAST_FOUND_BLOCK 0x00000010
|
sl@0
|
75 |
/* TME default values */
|
sl@0
|
76 |
#define TME_LUT_ENTRIES_DEFAULT 32007
|
sl@0
|
77 |
#define TME_REHASHING_VALUE_DEFAULT 1
|
sl@0
|
78 |
#define TME_SHARED_MEMORY_BLOCKS_DEFAULT 16000
|
sl@0
|
79 |
#define TME_BLOCK_SIZE_DEFAULT 64
|
sl@0
|
80 |
#define TME_EXTRA_SEGMENT_SIZE_DEFAULT 0
|
sl@0
|
81 |
#define TME_LOOKUP_CODE_DEFAULT 0
|
sl@0
|
82 |
#define TME_OUT_LUT_EXEC_DEFAULT 0
|
sl@0
|
83 |
#define TME_DEFAULT_EXEC_DEFAULT 0
|
sl@0
|
84 |
#define TME_MAX_FILL_STATE_DEFAULT 15000
|
sl@0
|
85 |
|
sl@0
|
86 |
#define IS_VALIDATED(src,index) (src&(1<<index))
|
sl@0
|
87 |
|
sl@0
|
88 |
#define VALIDATE(src,index) src|=(1<<index);
|
sl@0
|
89 |
|
sl@0
|
90 |
|
sl@0
|
91 |
#define FORCE_NO_DELETION(timestamp) (struct timeval*)(timestamp)->tv_sec=0x7fffffff;
|
sl@0
|
92 |
|
sl@0
|
93 |
struct __TME_DATA;
|
sl@0
|
94 |
|
sl@0
|
95 |
/* TME callback prototypes */
|
sl@0
|
96 |
typedef uint32 (*lut_fcn)(uint8 *key, struct __TME_DATA *data,MEM_TYPE *mem_ex, struct time_conv *time_ref );
|
sl@0
|
97 |
typedef uint32 (*exec_fcn)(uint8 *block, uint32 pkt_size, struct __TME_DATA *data, MEM_TYPE *mem_ex, uint8 *mem_data);
|
sl@0
|
98 |
|
sl@0
|
99 |
/* DO NOT MODIFY THIS STRUCTURE!!!! GV */
|
sl@0
|
100 |
typedef struct __RECORD
|
sl@0
|
101 |
|
sl@0
|
102 |
{
|
sl@0
|
103 |
uint32 block;
|
sl@0
|
104 |
uint32 exec_fcn;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
RECORD, *PRECORD;
|
sl@0
|
107 |
|
sl@0
|
108 |
/* TME data registers */
|
sl@0
|
109 |
struct __TME_DATA
|
sl@0
|
110 |
{
|
sl@0
|
111 |
uint32 lut_entries;
|
sl@0
|
112 |
uint32 max_fill_state;
|
sl@0
|
113 |
uint32 rehashing_value;
|
sl@0
|
114 |
uint32 key_len;
|
sl@0
|
115 |
uint32 shared_memory_blocks;
|
sl@0
|
116 |
uint32 filled_entries;
|
sl@0
|
117 |
uint32 block_size;
|
sl@0
|
118 |
uint32 extra_segment_size;
|
sl@0
|
119 |
uint32 filled_blocks;
|
sl@0
|
120 |
lut_fcn lookup_code;
|
sl@0
|
121 |
uint32 default_exec;
|
sl@0
|
122 |
uint32 out_lut_exec;
|
sl@0
|
123 |
uint8 *lut_base_address;
|
sl@0
|
124 |
uint8 *shared_memory_base_address;
|
sl@0
|
125 |
uint8 *extra_segment_base_address;
|
sl@0
|
126 |
struct timeval last_read;
|
sl@0
|
127 |
uint32 enable_deletion;
|
sl@0
|
128 |
uint8 *last_found;
|
sl@0
|
129 |
};
|
sl@0
|
130 |
|
sl@0
|
131 |
typedef struct __TME_DATA TME_DATA,*PTME_DATA;
|
sl@0
|
132 |
|
sl@0
|
133 |
|
sl@0
|
134 |
|
sl@0
|
135 |
/* TME core */
|
sl@0
|
136 |
typedef struct __TME_CORE
|
sl@0
|
137 |
{
|
sl@0
|
138 |
uint32 working;
|
sl@0
|
139 |
uint32 active;
|
sl@0
|
140 |
uint32 validated_blocks;
|
sl@0
|
141 |
TME_DATA block_data[MAX_TME_DATA_BLOCKS];
|
sl@0
|
142 |
uint32 active_read;
|
sl@0
|
143 |
|
sl@0
|
144 |
} TME_CORE, *PTME_CORE;
|
sl@0
|
145 |
|
sl@0
|
146 |
static __inline int32 IS_DELETABLE(void *timestamp, TME_DATA *data)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
struct timeval *ts=(struct timeval*)timestamp;
|
sl@0
|
149 |
|
sl@0
|
150 |
if (data->enable_deletion==FALSE)
|
sl@0
|
151 |
return FALSE;
|
sl@0
|
152 |
if (data->filled_entries<data->max_fill_state)
|
sl@0
|
153 |
return FALSE;
|
sl@0
|
154 |
if ((ts->tv_sec+DELTA_READ)<data->last_read.tv_sec)
|
sl@0
|
155 |
return TRUE;
|
sl@0
|
156 |
return FALSE;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
/* functions to manage TME */
|
sl@0
|
160 |
uint32 init_tme_block(TME_CORE *tme, uint32 block);
|
sl@0
|
161 |
uint32 validate_tme_block(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 block, uint32 mem_ex_offset);
|
sl@0
|
162 |
uint32 lookup_frontend(MEM_TYPE *mem_ex, TME_CORE *tme,uint32 mem_ex_offset, struct time_conv *time_ref);
|
sl@0
|
163 |
uint32 execute_frontend(MEM_TYPE *mem_ex, TME_CORE *tme, uint32 pkt_size,uint32 offset);
|
sl@0
|
164 |
uint32 set_active_tme_block(TME_CORE *tme, uint32 block);
|
sl@0
|
165 |
uint32 init_extended_memory(uint32 size, MEM_TYPE *mem_ex);
|
sl@0
|
166 |
uint32 reset_tme(TME_CORE *tme);
|
sl@0
|
167 |
uint32 get_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 *rval);
|
sl@0
|
168 |
uint32 set_tme_block_register(TME_DATA *data,MEM_TYPE *mem_ex,uint32 rgstr,uint32 value, int32 init);
|
sl@0
|
169 |
uint32 set_active_read_tme_block(TME_CORE *tme, uint32 block);
|
sl@0
|
170 |
uint32 set_autodeletion(TME_DATA *data, uint32 value);
|
sl@0
|
171 |
|
sl@0
|
172 |
/* function mappers */
|
sl@0
|
173 |
lut_fcn lut_fcn_mapper(uint32 index);
|
sl@0
|
174 |
exec_fcn exec_fcn_mapper(uint32 index);
|
sl@0
|
175 |
|
sl@0
|
176 |
#endif |