Debian Codegraph @

protolib/src/sim/ns/nsRouteMgr.cpp

raw
1 #include "protoRouteMgr.h"
2 //#include "protoRouteTable.h"
3 //#include "protoSim.h"
4
5 /**
6 * @class NsRouteMgr
7 *
8 * @brief NS Route manager
9 */
10 class NsRouteMgr : public ProtoRouteMgr
11 {
12 public:
13 NsRouteMgr();
14 ~NsRouteMgr();
15 virtual bool Open(const void* userData = NULL);
16 virtual bool IsOpen() const {return (0 != node_id);}
17 virtual void Close();
18
19 virtual bool GetAllRoutes(ProtoAddress::Type addrType,
20 ProtoRouteTable& routeTable);
21
22 virtual bool GetRoute(const ProtoAddress& dst,
23 unsigned int prefixLen,
24 ProtoAddress& gw,
25 unsigned int& ifIndex,
26 int& metric);
27
28 virtual bool SetRoute(const ProtoAddress& dst,
29 unsigned int prefixLen,
30 const ProtoAddress& gw,
31 unsigned int ifIndex = 0,
32 int metric = -1);
33
34 virtual bool DeleteRoute(const ProtoAddress& dst,
35 unsigned int prefixLen,
36 const ProtoAddress& gw,
37 unsigned int ifIndex = 0);
38 virtual bool SetForwarding(bool state);
39
40 bool GetInterfaceAddressList(unsigned int ifIndex,
41 ProtoAddress::Type addrType,
42 ProtoAddressList& theAddress);
43 unsigned int GetInterfaceIndex(const char* interfaceName);
44 bool GetInterfaceName(unsigned int interfaceIndex,
45 char* buffer,
46 unsigned int buflen);
47
48 private:
49 int node_id;
50 int forwarding_on;
51 ProtoRouteTable local_table;
52 }; //end class NsRouteMgr
53
54 ProtoRouteMgr* ProtoRouteMgr::Create(Type /*type*/)
55 {
56 return (ProtoRouteMgr*)(new NsRouteMgr);
57 } // end ProtoRouteMgr::Create()
58
59 NsRouteMgr::NsRouteMgr()
60 : node_id(NULL)
61 {
62 }
63
64 NsRouteMgr::~NsRouteMgr()
65 {
66 Close();
67 }
68
69 bool NsRouteMgr::Open(const void* userData)
70 {
71 if (userData != NULL)
72 {
73 node_id = *(int*)userData;
74 }
75 else
76 {
77 TRACE("NsRouteMgr::Open: Error, called with NULL pointer!\n");
78 return false;
79 }
80 local_table.Init();
81 return true;
82 }
83
84 void NsRouteMgr::Close()
85 {
86 local_table.Destroy();
87 node_id = NULL;
88 }
89
90 bool NsRouteMgr::GetRoute(const ProtoAddress& dst,
91 unsigned int prefixLen,
92 ProtoAddress& gw,
93 unsigned int& ifIndex,
94 int& metric)
95 {
96 return local_table.FindRoute(dst,prefixLen,gw,ifIndex,metric);
97 }
98
99 bool NsRouteMgr::SetRoute(const ProtoAddress& dst,
100 unsigned int prefixLen,
101 const ProtoAddress& gw,
102 unsigned int ifIndex,
103 int metric)
104 {
105 return local_table.SetRoute(dst,prefixLen,gw,ifIndex,metric);
106 } // end NsRouteMgr::SetRoute()
107
108 bool NsRouteMgr::DeleteRoute(const ProtoAddress& dst,
109 unsigned int prefixLen,
110 const ProtoAddress& gw,
111 unsigned int ifIndex)
112 {
113 return local_table.DeleteRoute(dst,prefixLen,&gw);
114 } // end NsRouteMgr::DeleteRoute()
115
116 bool NsRouteMgr::GetAllRoutes(ProtoAddress::Type addrType,
117 ProtoRouteTable& routeTable)
118 {
119 return false; //this function does not currently work in ns
120 }// end NsRouteMgr::GetAllRoutes
121
122 bool NsRouteMgr::GetInterfaceAddressList(unsigned int ifIndex,
123 ProtoAddress::Type addrType,
124 ProtoAddressList& addrList)
125 {
126 //this is going to be a little trickier
127 ProtoAddress ifAddr;
128 ifAddr.SimSetAddress(node_id);
129 return (addrList.Insert(ifAddr));
130 } // end NsRouteMgr::GetInterfaceAddress()
131
132 unsigned int NsRouteMgr::GetInterfaceIndex(const char* interfaceName)
133 {
134 return 1;
135 } // end NsRouteMgr::GetInterfaceIndex()
136
137 bool NsRouteMgr::GetInterfaceName(unsigned int interfaceIndex,
138 char* buffer,
139 unsigned int buflen)
140 {
141 snprintf(buffer,buflen,"%d",node_id);
142 return true;
143 } // end NsRouteMgr::GetInterfaceName()
144
145 bool NsRouteMgr::SetForwarding(bool state)
146 {
147 forwarding_on = state;
148 return true;
149 } // end NsRouteMgr::SetForwarding()