forked from awm22/NetFPGA-P33
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sr_integration.c
223 lines (190 loc) · 7.37 KB
/
sr_integration.c
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
/*-----------------------------------------------------------------------------
* file: sr_integration.c
* date: Tue Feb 03 11:29:17 PST 2004
* Author: Martin Casado <[email protected]>
*
* Description:
*
* Methods called by the lowest-level of the network system to talk with
* the network subsystem.
*
* This is the entry point of integration for the network layer.
*
*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
#include "sr_vns.h"
#include "sr_base_internal.h"
#ifdef _CPUMODE_
#include "sr_cpu_extension_nf2.h"
#endif
/*-----------------------------------------------------------------------------
* Method: sr_integ_init(..)
* Scope: global
*
*
* First method called during router initialization. Called before connecting
* to VNS, reading in hardware information etc.
*
*---------------------------------------------------------------------------*/
void sr_integ_init(struct sr_instance* sr)
{
printf(" ** sr_integ_init(..) called \n");
} /* -- sr_integ_init -- */
/*-----------------------------------------------------------------------------
* Method: sr_integ_hw_setup(..)
* Scope: global
*
* Called after all initial hardware information (interfaces) have been
* received. Can be used to start subprocesses (such as dynamic-routing
* protocol) which require interface information during initialization.
*
*---------------------------------------------------------------------------*/
void sr_integ_hw_setup(struct sr_instance* sr)
{
printf(" ** sr_integ_hw(..) called \n");
} /* -- sr_integ_hw_setup -- */
/*---------------------------------------------------------------------
* Method: sr_integ_input(struct sr_instance*,
* uint8_t* packet,
* char* interface)
* Scope: Global
*
* This method is called each time the router receives a packet on the
* interface. The packet buffer, the packet length and the receiving
* interface are passed in as parameters. The packet is complete with
* ethernet headers.
*
* Note: Both the packet buffer and the character's memory are handled
* by sr_vns_comm.c that means do NOT delete either. Make a copy of the
* packet instead if you intend to keep it around beyond the scope of
* the method call.
*
*---------------------------------------------------------------------*/
void sr_integ_input(struct sr_instance* sr,
const uint8_t * packet/* borrowed */,
unsigned int len,
const char* interface/* borrowed */)
{
/* -- INTEGRATION PACKET ENTRY POINT!-- */
printf(" ** sr_integ_input(..) called \n");
sr_integ_low_level_output(sr /* borrowed */,
packet /* borrowed */ ,
len,
interface /* borrowed */);
} /* -- sr_integ_input -- */
/*-----------------------------------------------------------------------------
* Method: sr_integ_add_interface(..)
* Scope: global
*
* Called for each interface read in during hardware initialization.
* struct sr_vns_if is defined in sr_base_internal.h
*
*---------------------------------------------------------------------------*/
void sr_integ_add_interface(struct sr_instance* sr,
struct sr_vns_if* vns_if/* borrowed */)
{
printf(" ** sr_integ_add_interface(..) called \n");
} /* -- sr_integ_add_interface -- */
struct sr_instance* get_sr() {
struct sr_instance* sr;
sr = sr_get_global_instance( NULL );
assert( sr );
return sr;
}
/*-----------------------------------------------------------------------------
* Method: sr_integ_low_level_output(..)
* Scope: global
*
* Send a packet to VNS to be injected into the topology
*
*---------------------------------------------------------------------------*/
int sr_integ_low_level_output(struct sr_instance* sr /* borrowed */,
uint8_t* buf /* borrowed */ ,
unsigned int len,
const char* iface /* borrowed */)
{
#ifdef _CPUMODE_
return sr_cpu_output(sr, buf /*lent*/, len, iface);
#else
return sr_vns_send_packet(sr, buf /*lent*/, len, iface);
#endif /* _CPUMODE_ */
} /* -- sr_vns_integ_output -- */
/*-----------------------------------------------------------------------------
* Method: sr_integ_destroy(..)
* Scope: global
*
* For memory deallocation pruposes on shutdown.
*
*---------------------------------------------------------------------------*/
void sr_integ_destroy(struct sr_instance* sr)
{
printf(" ** sr_integ_destroy(..) called \n");
} /* -- sr_integ_destroy -- */
/*-----------------------------------------------------------------------------
* Method: sr_integ_findsrcip(..)
* Scope: global
*
* Called by the transport layer for outgoing packets generated by the
* router. Expects source address in network byte order.
*
*---------------------------------------------------------------------------*/
uint32_t sr_integ_findsrcip(uint32_t dest /* nbo */)
{
fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
fprintf(stderr, "!!! Tranport layer called ip_findsrcip(..) this must be !!!\n");
fprintf(stderr, "!!! defined to return the correct source address !!!\n");
fprintf(stderr, "!!! given a destination !!!\n ");
fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
assert(0);
/* --
* e.g.
*
* struct sr_instance* sr = sr_get_global_instance();
* struct my_router* mr = (struct my_router*)
* sr_get_subsystem(sr);
* return my_findsrcip(mr, dest);
* -- */
return 0;
} /* -- ip_findsrcip -- */
/*-----------------------------------------------------------------------------
* Method: sr_integ_ip_output(..)
* Scope: global
*
* Called by the transport layer for outgoing packets that need IP
* encapsulation.
*
*---------------------------------------------------------------------------*/
uint32_t sr_integ_ip_output(uint8_t* payload /* given */,
uint8_t proto,
uint32_t src, /* nbo */
uint32_t dest, /* nbo */
int len)
{
fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
fprintf(stderr, "!!! Tranport layer called sr_integ_ip_output(..) !!!\n");
fprintf(stderr, "!!! this must be defined to handle the network !!!\n ");
fprintf(stderr, "!!! level functionality of transport packets !!!\n ");
fprintf(stderr, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
assert(0);
/* --
* e.g.
*
* struct sr_instance* sr = sr_get_global_instance();
* struct my_router* mr = (struct my_router*)
* sr_get_subsystem(sr);
* return my_ip_output(mr, payload, proto, src, dest, len);
* -- */
return 0;
} /* -- ip_integ_route -- */
/*-----------------------------------------------------------------------------
* Method: sr_integ_close(..)
* Scope: global
*
* Called when the router is closing connection to VNS.
*
*---------------------------------------------------------------------------*/
void sr_integ_close(struct sr_instance* sr)
{
printf(" ** sr_integ_close(..) called \n");
} /* -- sr_integ_close -- */