Debian Codegraph @

protolib/src/sim/opnet/11.5/opnetProtoRouteMgr.ex.cpp

raw
1 // LP 7-16-04 - replaced
2 // #include "OpnetProtoRouteMgr.h"
3 #include "opnetProtoRouteMgr.h"
4 // end LP
5
6 OpnetProtoRouteMgr::OpnetProtoRouteMgr()
7 {
8 #ifdef OP_DEBUG2
9 printf("\t\tOpnetProtoRouteMgr::OpnetProtoRouteMgr()\n");
10 #endif
11 // localTable.Init();
12 }
13
14 OpnetProtoRouteMgr::~OpnetProtoRouteMgr()
15 {
16 }
17
18 // LP 4-22-04 - replaced for new ProtRouteMgr.h
19 /*
20 bool OpnetProtoRouteMgr::Open()
21 {
22 #ifdef OP_DEBUG1
23 printf("\t\tOpnetProtoRouteMgr::Open()\n");
24 #endif
25 bool r_val = OPC_TRUE;
26 return (r_val);
27 }
28 */
29
30 bool OpnetProtoRouteMgr::Open(const void* userData)
31 {
32 #ifdef OP_DEBUG1
33 printf("\t\tOpnetProtoRouteMgr::Open()\n");
34 #endif
35 bool r_val = OPC_TRUE;
36 return (r_val);
37 }
38
39 // end LP
40
41 bool OpnetProtoRouteMgr::Open(IpT_Cmn_Rte_Table * cmn_rte_table, int nodeId,
42 IpT_Rte_Proc_Id olsr_protocol_id, IpT_Interface_Info* ip_intf_pnt)
43 {
44 opnet_cmn_route_table = cmn_rte_table;
45 my_node_id = nodeId;
46 my_protocol_id = olsr_protocol_id;
47 my_ip_interface_pnt = ip_intf_pnt;
48 #ifdef OP_DEBUG1
49 printf("Node %d - OpnetProtoRouteMgr::Open() - cmn_route_table = %ld, protocol_id = %I64d, ip_interf_pnt = %ld\n",
50 my_node_id, opnet_cmn_route_table, my_protocol_id, my_ip_interface_pnt);
51 #endif
52
53 bool r_value = OPC_TRUE;
54 return r_value;
55 }
56
57
58 bool OpnetProtoRouteMgr::IsOpen() const
59 {
60 if (opnet_cmn_route_table != OPC_NIL)
61 return (OPC_TRUE);
62 else
63 return (OPC_FALSE);
64 }
65
66 void OpnetProtoRouteMgr::Close()
67 {
68 }
69
70 bool OpnetProtoRouteMgr::GetAllRoutes(ProtoAddress::Type addrType,
71 ProtoRouteTable& routeTable)
72 {
73 // This function is called by the nrlOLSR.pr.c as a part of
74 // the nrlolsr->Start(). When running using ns, this does nothing.
75 // We may not need this function for Opnet either. So, it's a
76 // place-holder for now. LP 3-8-04
77 #ifdef OP_DEBUG1
78 printf("\t\tOpnetProtoRouteMgr::GetAllRoutes().\n");
79 #endif
80
81 return OPC_TRUE;
82 }
83
84 bool OpnetProtoRouteMgr::GetRoute(const ProtoAddress& dst,
85 unsigned int prefixLen,
86 ProtoAddress& gw,
87 unsigned int& ifIndex,
88 int& metric)
89 {
90 #ifdef OP_DEBUG1
91 printf("\t\tOpnetProtoRouteMgr::GetRoute() - Not used yet. \n");
92 #endif
93 return OPC_TRUE;
94 }
95
96 bool OpnetProtoRouteMgr::SetRoute(const ProtoAddress& dst,
97 unsigned int prefixLen,
98 const ProtoAddress& gw,
99 unsigned int ifIndex,
100 int metric)
101 {
102 /* Ip_Cmn_Rte_Table_Entry_Add (
103 opnet_cmn_route_table, // pointer to the IP Common Route Table
104 src_obj_ptn, // pointer to the entry in the source routing protocol, may be a function
105 dest, // IP address ofthe destination network
106 mask, // subnet mask of the destination network
107 next_hop, // IP address ofthe interface that should be used as thenext hop for the destination
108 port_info, // contans the "addr_index" of the interface used t o reach the next hop
109 metric, // metric assigned to this next hop
110 my_protocol_id, // the unique routing protocol id
111 admin_distance // the preference asssociated with this entry
112 );
113 */
114 Compcode comp;
115 IpT_Address dest, mask, next_hop;
116 IpT_Port_Info port_info;
117 int admin_distance;
118
119
120 dest = (IpT_Address) dst.SimGetAddress();
121
122 /* from Jim Hauser's */
123 if(dest ==INADDR_ANY)
124 mask = NETMASK_DEFAULT;
125 else
126 mask = NETMASK_HOST;
127 /* end JH */
128
129 port_info.intf_tbl_index = my_ip_interface_pnt->phys_intf_info_ptr->ip_addr_index; // JPH changed addr_index to ip_addr_index
130 port_info.output_info.intf_name = "WLAN"; // JPH output_info union added
131 port_info.minor_port = IPC_SUBINTF_PHYS_INTF; // This value is -1. LP 7-23-04 - added
132
133 next_hop = (IpT_Address) gw.SimGetAddress();
134 if (next_hop == 0) // the dest is directly connected to this node
135 next_hop = (IpT_Address) dst.SimGetAddress();
136
137 admin_distance = 0;
138
139 #ifdef OP_DEBUG1
140 printf("Node %d - OpnetProtoRouteMgr::SetRoute() - dest = %u, next-hop = %u\n",
141 my_node_id, dest, next_hop);
142
143 printf("\t\t - port_info->intf_tbl_index = %hd, metrix = %d, admin_distance = %d\n",
144 port_info.intf_tbl_index, metric, admin_distance);
145 #endif
146
147 // LP 3-16-04. Note that the source_obj_ptr is set to OPC_NIL here. That parameter
148 // would be used in Ip_Cmn_Rte_Table_Entry_Add() when creating Rte_Table_Entry.
149 // In the Entry creation process, if the new route is a directly connected route, the
150 // new_entry->route_src_obj_ptr = new_entry; else, it = source_obj_ptr. Need to
151 // double check if OPC_NIL is OK for OLSR case.
152
153 //comp = Ip_Cmn_Rte_Table_Entry_Add ( JPH 8/17/2006 - add IPC_CMN_RTE_TABLE_ENTRY_ADD_INDIRECT_NEXTHOP_OPTION
154 comp = Inet_Cmn_Rte_Table_Entry_Add_Options (
155 opnet_cmn_route_table,
156 my_ip_interface_pnt,
157 //dest,
158 //mask,
159 ip_cmn_rte_table_v4_dest_prefix_create(dest,mask),
160 inet_address_from_ipv4_address_create(next_hop),
161 port_info,
162 metric,
163 my_protocol_id,
164 admin_distance,
165 IPC_CMN_RTE_TABLE_ENTRY_ADD_INDIRECT_NEXTHOP_OPTION);
166
167 if (op_prg_odb_ltrace_active ("olsr route table"))
168 ip_cmn_rte_table_print (opnet_cmn_route_table);
169 return ((bool)comp);
170 }
171
172 bool OpnetProtoRouteMgr::DeleteRoute(const ProtoAddress& dst,
173 unsigned int prefixLen,
174 const ProtoAddress& gw,
175 unsigned int ifIndex)
176 {
177 Compcode comp;
178 IpT_Address dest, mask, next_hop;
179 IpT_Port_Info port_info;
180 int admin_distance;
181
182 dest = (IpT_Address) dst.SimGetAddress();
183
184 #ifdef OP_DEBUG1
185 printf("Node %d - OpnetProtoRouteMgr::DeleteRoute() - dest = %u\n", my_node_id, dest);
186 #endif
187
188 /* from Jim Hauser's */
189 if(dest ==INADDR_ANY)
190 mask = NETMASK_DEFAULT;
191 else
192 mask = NETMASK_HOST;
193
194 /* end JH */
195
196 port_info.intf_tbl_index = my_ip_interface_pnt->phys_intf_info_ptr->ip_addr_index; // JPH addr_index changed to ip_addr_index
197 port_info.output_info.intf_name = "WLAN"; // JPH added output_info union
198
199 next_hop = (IpT_Address) gw.SimGetAddress();
200 if (next_hop == 0) // - the dest is directly connected to this node
201 next_hop = (IpT_Address) dst.SimGetAddress();
202 admin_distance = 0;
203
204
205 /* LP - Note that the following command delete the entire destination entry
206 from the IP Route Table. If we want to delte only a next hop from the entry from
207 IP Route Table, the command would be Ip_comn_Rte_Table_Entry_Delete) */
208
209 comp = Ip_Cmn_Rte_Table_Route_Delete (
210 opnet_cmn_route_table,
211 dest,
212 mask,
213 my_protocol_id);
214
215
216 if (op_prg_odb_ltrace_active ("olsr route table"))
217 ip_cmn_rte_table_print (opnet_cmn_route_table);
218 return ((bool)comp);
219 }
220
221 bool OpnetProtoRouteMgr::SetForwarding(bool state)
222 {
223 forwardingOn = state;
224 return OPC_TRUE;
225 }
226
227 OpnetProtoRouteMgr* OpnetProtoRouteMgr::Create()
228 {
229 #ifdef OP_DEBUG1
230 printf("\t\tOpnetProtoRouteMgr::Create()\n");
231 #endif
232 return (new OpnetProtoRouteMgr);
233 } // end OpnetProtoRouteMgr::Create()
234
235
236 ProtoRouteMgr* ProtoRouteMgr::Create()
237 {
238 return (ProtoRouteMgr*)(new OpnetProtoRouteMgr);
239 } // end ProtoRouteMgr::Create()
240
241
242 // LP 4-22-04 - added
243 bool OpnetProtoRouteMgr::GetInterfaceAddressList(unsigned int ifIndex,
244 ProtoAddress::Type addrType,
245 ProtoAddress::List& addrList)
246 {
247 FIN (OpnetProtoRouteMgr::GetLocalAddress());
248 IpT_Interface_Info * ip_intf_pnt;
249 ip_intf_pnt = this->GetIntfInfoPnt();
250 IpT_Address IpAddr = ip_intf_pnt->addr_range_ptr->address;
251 // IpT_Address IPSubnetMask = ip_intf_pnt->addr_range_ptr->subnet_mask;
252 ProtoAddress ifAddr;
253 ifAddr.SimSetAddress((SIMADDR)IpAddr);
254 bool result = addrList.Insert(ifAddr);
255 if (!result)
256 PLOG(PL_ERROR, "OpnetProtoRouteMgr::GetLocalAddress() error: "
257 "unable to add addr to list\n");
258 #ifdef OP_DEBUG1
259 printf("OpnetProtoRouteMgr::GetLocalAddress(my_Ip_Addr = %u)\n", IpAddr);
260 #endif
261 FRET (result);
262 } // end OpnetProtoRouteMgr::GetInterfaceAddress()
263
264 // LP 4-19-04 - added
265
266
267 unsigned int OpnetProtoRouteMgr::GetInterfaceIndex(const char* interfaceName)
268 {
269 // LP 5-4-04 - replaced
270 // return OPC_NIL;
271 FIN (OpnetProtoRouteMgr::GetInterfaceIndex());
272 IpT_Interface_Info * ip_intf_pnt;
273 ip_intf_pnt = this->GetIntfInfoPnt();
274
275 // Note that in Opnet, the interface index starts from 0. However,
276 // in NRL-OLSR code, the interface index is expected to start from 1.
277 // So, we incrementthe Opnet index by 1 here.
278
279 int index = ip_intf_pnt->phys_intf_info_ptr->ip_addr_index + 1; /* JPH addr_index changed to ip_addr_index */
280 #ifdef OP_DEBUG1
281 printf("Node %d - opnetProtoRouteMgr.pr.c - GetInterfaceIndex() - name = %s, index = %d\n",
282 this->getNodeId(), interfaceName, index);
283 #endif
284 FRET ( (unsigned int) index);
285 // end LP 5-4-04
286
287 }
288
289
290 bool OpnetProtoRouteMgr::GetInterfaceName(unsigned int interfaceIndex,
291 char* buffer,
292 unsigned int buflen)
293 {
294 // LP 5-4-04 - replaced
295 // return OPC_TRUE;
296
297 FIN (OpnetProtoRouteMgr::GetInterfaceName());
298 IpT_Interface_Info * ip_intf_pnt;
299 ip_intf_pnt = this->GetIntfInfoPnt();
300 strcpy (buffer, ip_intf_pnt->full_name);
301 #ifdef OP_DEBUG1
302 printf("Node %d - opnetProtoRouteMgr.pr.c - GetInterfaceName() - name = %s\n",
303 this->getNodeId(), buffer);
304 #endif
305 FRET (OPC_TRUE);
306
307 // end LP 5-4-04
308 }
309
310 // end LP 4-19-04
311
312 /* OPNET data type
313 typedef unsigned int IpT_Address;
314 typedef IpT_Address IpT_Router_Id;
315 typedef OpT_uInt8 InetT_Subnet_Mask;
316
317 typedef struct InetT_Address
318 {
319 OpT_uInt8 addr_family; / InetT_Addr_Family value /
320 union
321 {
322 IpT_Address ipv4_addr; / Ipv4 address. /
323 struct Ipv6T_Address* ipv6_addr_ptr; / Ipv6 address. /
324 } address;
325 } InetT_Address;
326
327 */