Debian Codegraph @

protolib/src/sim/opnet/12.0/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 // JPH - 12/6/06
119 DeleteRoute(dst, prefixLen, gw, ifIndex);
120
121 dest = (IpT_Address) dst.SimGetAddress();
122
123 /* from Jim Hauser's */
124 if(dest ==INADDR_ANY)
125 mask = NETMASK_DEFAULT;
126 else
127 mask = NETMASK_HOST;
128 /* end JH */
129
130 port_info.intf_tbl_index = my_ip_interface_pnt->phys_intf_info_ptr->ip_addr_index; // JPH changed addr_index to ip_addr_index
131 port_info.output_info.intf_name = "WLAN"; // JPH output_info union added
132 port_info.minor_port = IPC_SUBINTF_PHYS_INTF; // This value is -1. LP 7-23-04 - added
133
134 next_hop = (IpT_Address) gw.SimGetAddress();
135 if (next_hop == 0) // the dest is directly connected to this node
136 next_hop = (IpT_Address) dst.SimGetAddress();
137
138 admin_distance = 0;
139
140 #ifdef OP_DEBUG1
141 printf("Node %d - OpnetProtoRouteMgr::SetRoute() - dest = %u, next-hop = %u\n",
142 my_node_id, dest, next_hop);
143
144 printf("\t\t - port_info->intf_tbl_index = %hd, metrix = %d, admin_distance = %d\n",
145 port_info.intf_tbl_index, metric, admin_distance);
146 #endif
147
148 // LP 3-16-04. Note that the source_obj_ptr is set to OPC_NIL here. That parameter
149 // would be used in Ip_Cmn_Rte_Table_Entry_Add() when creating Rte_Table_Entry.
150 // In the Entry creation process, if the new route is a directly connected route, the
151 // new_entry->route_src_obj_ptr = new_entry; else, it = source_obj_ptr. Need to
152 // double check if OPC_NIL is OK for OLSR case.
153
154 //comp = Ip_Cmn_Rte_Table_Entry_Add ( JPH 8/17/2006 - add IPC_CMN_RTE_TABLE_ENTRY_ADD_INDIRECT_NEXTHOP_OPTION
155 comp = Inet_Cmn_Rte_Table_Entry_Add_Options (
156 opnet_cmn_route_table,
157 my_ip_interface_pnt,
158 //dest,
159 //mask,
160 ip_cmn_rte_table_v4_dest_prefix_create(dest,mask),
161 inet_address_from_ipv4_address_create(next_hop),
162 port_info,
163 metric,
164 my_protocol_id,
165 admin_distance,
166 IPC_CMN_RTE_TABLE_ENTRY_ADD_INDIRECT_NEXTHOP_OPTION);
167
168 if (op_prg_odb_ltrace_active ("olsr route table"))
169 ip_cmn_rte_table_print (opnet_cmn_route_table);
170 return ((bool)comp);
171 }
172
173 bool OpnetProtoRouteMgr::DeleteRoute(const ProtoAddress& dst,
174 unsigned int prefixLen,
175 const ProtoAddress& gw,
176 unsigned int ifIndex)
177 {
178 Compcode comp;
179 IpT_Address dest, mask, next_hop;
180 IpT_Port_Info port_info;
181 int admin_distance;
182
183 dest = (IpT_Address) dst.SimGetAddress();
184
185 #ifdef OP_DEBUG1
186 printf("Node %d - OpnetProtoRouteMgr::DeleteRoute() - dest = %u\n", my_node_id, dest);
187 #endif
188
189 /* from Jim Hauser's */
190 if(dest ==INADDR_ANY)
191 mask = NETMASK_DEFAULT;
192 else
193 mask = NETMASK_HOST;
194
195 /* end JH */
196
197 port_info.intf_tbl_index = my_ip_interface_pnt->phys_intf_info_ptr->ip_addr_index; // JPH addr_index changed to ip_addr_index
198 port_info.output_info.intf_name = "WLAN"; // JPH added output_info union
199
200 next_hop = (IpT_Address) gw.SimGetAddress();
201 if (next_hop == 0) // - the dest is directly connected to this node
202 next_hop = (IpT_Address) dst.SimGetAddress();
203 admin_distance = 0;
204
205
206 /* LP - Note that the following command delete the entire destination entry
207 from the IP Route Table. If we want to delte only a next hop from the entry from
208 IP Route Table, the command would be Ip_comn_Rte_Table_Entry_Delete) */
209
210 comp = Ip_Cmn_Rte_Table_Route_Delete (
211 opnet_cmn_route_table,
212 dest,
213 mask,
214 my_protocol_id);
215
216
217 if (op_prg_odb_ltrace_active ("olsr route table"))
218 ip_cmn_rte_table_print (opnet_cmn_route_table);
219 return ((bool)comp);
220 }
221
222 bool OpnetProtoRouteMgr::SetForwarding(bool state)
223 {
224 forwardingOn = state;
225 return OPC_TRUE;
226 }
227
228 OpnetProtoRouteMgr* OpnetProtoRouteMgr::Create()
229 {
230 #ifdef OP_DEBUG1
231 printf("\t\tOpnetProtoRouteMgr::Create()\n");
232 #endif
233 return (new OpnetProtoRouteMgr);
234 } // end OpnetProtoRouteMgr::Create()
235
236
237 ProtoRouteMgr* ProtoRouteMgr::Create()
238 {
239 return (ProtoRouteMgr*)(new OpnetProtoRouteMgr);
240 } // end ProtoRouteMgr::Create()
241
242
243 // LP 4-22-04 - added
244 // JPH 11-3-06 modified
245 //bool OpnetProtoRouteMgr::GetInterfaceAddress(unsigned int ifIndex,
246 // ProtoAddress::Type addrType,
247 // ProtoAddress& theAddress)
248 bool OpnetProtoRouteMgr::GetInterfaceAddressList(unsigned int ifIndex,
249 ProtoAddress::Type addrType,
250 ProtoAddressList& addrList)
251 {
252 // FIN (OpnetProtoRouteMgr::GetLocalAddress()); JPH
253 FIN (OpnetProtoRouteMgr::GetInterfaceAddressList(ifIndex,addrType,addrList))
254 IpT_Interface_Info * ip_intf_pnt;
255 ip_intf_pnt = this->GetIntfInfoPnt();
256 IpT_Address IpAddr = ip_intf_pnt->addr_range_ptr->address;
257 // IpT_Address IPSubnetMask = ip_intf_pnt->addr_range_ptr->subnet_mask;
258 ProtoAddress ifAddr;
259 ifAddr.SimSetAddress((SIMADDR)IpAddr);
260 bool result = addrList.Insert(ifAddr);
261 if (!result)
262 PLOG(PL_ERROR, "OpnetProtoRouteMgr::GetLocalAddress() error: "
263 "unable to add addr to list\n");
264 #ifdef OP_DEBUG1
265 printf("OpnetProtoRouteMgr::GetLocalAddress(my_Ip_Addr = %u)\n", IpAddr);
266 #endif
267 FRET (result);
268
269
270 }
271
272 // LP 4-19-04 - added
273
274
275 unsigned int OpnetProtoRouteMgr::GetInterfaceIndex(const char* interfaceName)
276 {
277 // LP 5-4-04 - replaced
278 // return OPC_NIL;
279 FIN (OpnetProtoRouteMgr::GetInterfaceIndex());
280 IpT_Interface_Info * ip_intf_pnt;
281 ip_intf_pnt = this->GetIntfInfoPnt();
282
283 // Note that in Opnet, the interface index starts from 0. However,
284 // in NRL-OLSR code, the interface index is expected to start from 1.
285 // So, we incrementthe Opnet index by 1 here.
286
287 int index = ip_intf_pnt->phys_intf_info_ptr->ip_addr_index + 1; /* JPH addr_index changed to ip_addr_index */
288 #ifdef OP_DEBUG1
289 printf("Node %d - opnetProtoRouteMgr.pr.c - GetInterfaceIndex() - name = %s, index = %d\n",
290 this->getNodeId(), interfaceName, index);
291 #endif
292 FRET ( (unsigned int) index);
293 // end LP 5-4-04
294
295 }
296
297
298 bool OpnetProtoRouteMgr::GetInterfaceName(unsigned int interfaceIndex,
299 char* buffer,
300 unsigned int buflen)
301 {
302 // LP 5-4-04 - replaced
303 // return OPC_TRUE;
304
305 FIN (OpnetProtoRouteMgr::GetInterfaceName());
306 IpT_Interface_Info * ip_intf_pnt;
307 ip_intf_pnt = this->GetIntfInfoPnt();
308 strcpy (buffer, ip_intf_pnt->full_name);
309 #ifdef OP_DEBUG1
310 printf("Node %d - opnetProtoRouteMgr.pr.c - GetInterfaceName() - name = %s\n",
311 this->getNodeId(), buffer);
312 #endif
313 FRET (OPC_TRUE);
314
315 // end LP 5-4-04
316 }
317
318 // end LP 4-19-04
319
320 /* OPNET data type
321 typedef unsigned int IpT_Address;
322 typedef IpT_Address IpT_Router_Id;
323 typedef OpT_uInt8 InetT_Subnet_Mask;
324
325 typedef struct InetT_Address
326 {
327 OpT_uInt8 addr_family; / InetT_Addr_Family value /
328 union
329 {
330 IpT_Address ipv4_addr; / Ipv4 address. /
331 struct Ipv6T_Address* ipv6_addr_ptr; / Ipv6 address. /
332 } address;
333 } InetT_Address;
334
335 */