blob: 7e539eff61bbd402ca4c133f678bd7e16c606c33 [file] [log] [blame]
Alexander Afanasyev381dea02011-11-03 08:33:26 -07001from pybindgen import Module, FileCodeSink, param, retval, cppclass, typehandlers
2
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -08003from pybindgen.typehandlers.smart_ptr import StdSharedPtr
4
5from ns3_ptr import Ns3PtrMemoryPolicy
6
Alexander Afanasyev381dea02011-11-03 08:33:26 -07007import pybindgen.settings
8import warnings
9
Alexander Afanasyev381dea02011-11-03 08:33:26 -070010import sys
11
12def module_init():
Alexander Afanasyev6d98ac32012-06-06 13:01:48 -070013 root_module = Module('ns.ndnSIM', cpp_namespace='::ns3')
Alexander Afanasyev381dea02011-11-03 08:33:26 -070014 return root_module
15
16def register_types(module):
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -080017 module.add_class('ObjectBase', allow_subclassing=True, import_from_module='ns.core')
18 module.add_class('SimpleRefCount', automatic_type_narrowing=True, import_from_module='ns.core',
19 template_parameters=['ns3::Object', 'ns3::ObjectBase', 'ns3::ObjectDeleter'],
20 parent=module['ns3::ObjectBase'],
21 memory_policy=cppclass.ReferenceCountingMethodsPolicy(incref_method='Ref', decref_method='Unref', peekref_method='GetReferenceCount'))
22 module.add_class('Object', import_from_module='ns.core', parent=module['ns3::SimpleRefCount< ns3::Object, ns3::ObjectBase, ns3::ObjectDeleter >'])
23
24 module.add_class('TypeId', import_from_module='ns.core')
25 module.add_class('AttributeValue', import_from_module='ns.core')
26
27 module.add_class('NodeContainer', import_from_module='ns.network')
28 module.add_class('Node', import_from_module='ns.network', parent=module['ns3::Object'])
29 module.add_class('ApplicationContainer', import_from_module='ns.network')
30
31 def reg_ndn(module):
32 module.add_class('StackHelper')
33 module.add_class('FibHelper')
34 module.add_class('StrategyChoiceHelper')
35 module.add_class('AppHelper')
36 module.add_class('GlobalRoutingHelper')
37
38 module.add_class('L3Protocol', parent=module.get_root()['ns3::Object'])
39
40 module.add_class('Name')
41 module.add_class('Interest')
42 module.add_class('Data')
43 module.add_class('Face', memory_policy=StdSharedPtr('ns3::ndn::Face'))
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -080044
45 def reg_name(module):
46 module.add_class('Component')
47 reg_name(module.add_cpp_namespace('name'))
48
49 def reg_nfd(module):
50 module.add_class('Forwarder', memory_policy=StdSharedPtr('::ns3::ndn::nfd::Forwarder'), is_singleton=True)
51 module.add_class('Fib')
52 module.add_class('Pit')
53 module.add_class('Cs')
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -050054 module.add_class('FaceTable')
55 module.add_class('Face')
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -080056
57 def reg_fib(module):
58 module.add_class('Entry')#, memory_policy=StdSharedPtr('ns3::ndn::nfd::fib::Entry'))
59 module.add_class('NextHop')
60 module.add_class('NextHopList')
61 reg_fib(module.add_cpp_namespace('fib'))
62
63 def reg_pit(module):
64 module.add_class('Entry')#, memory_policy=StdSharedPtr('ns3::ndn::nfd::pit::Entry'))
65 reg_pit(module.add_cpp_namespace('pit'))
66
67 def reg_cs(module):
68 module.add_class('Entry')#, memory_policy=StdSharedPtr('ns3::ndn::nfd::cs::Entry'))
69 reg_cs(module.add_cpp_namespace('cs'))
70
71 reg_nfd(module.add_cpp_namespace('nfd'))
72 reg_ndn(module.add_cpp_namespace('ndn'))
Alexander Afanasyeva6cc9102013-07-15 18:44:24 -070073
Alexander Afanasyev381dea02011-11-03 08:33:26 -070074def register_methods(root_module):
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -080075 reg_other_modules(root_module)
76
77 def reg_stackhelper(cls):
78 cls.add_constructor([])
79
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -050080 cls.add_method('Install', retval('void'), [param('ns3::Ptr<ns3::Node>', 'node')], is_const=True)
81 cls.add_method('Install', retval('void'), [param('std::string const&', 'nodeName')], is_const=True)
82 cls.add_method('Install', retval('void'), [param('const ns3::NodeContainer&', 'c')], is_const=True)
83 cls.add_method('InstallAll', retval('void'), [], is_const=True)
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -080084
85 cls.add_method('SetDefaultRoutes', retval('void'), [param('bool', 'isEnabled', default_value='true')], is_const=True)
86 cls.add_method('SetStackAttributes',
87 retval('void'),
88 [param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'),
89 param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'),
90 param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'),
91 param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')])
92
93 cls.add_method('setCsSize', retval('void'), [param('size_t', 'maxSize')])
94 cls.add_method('SetOldContentStore',
95 retval('void'),
96 [param('const std::string&', 'contentStoreClass'),
97 param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'),
98 param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'),
99 param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'),
100 param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')])
101 reg_stackhelper(root_module['ns3::ndn::StackHelper'])
102
103 def reg_fibhelper(cls):
104 cls.add_method('AddRoute', retval('void'), [
105 param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'),
106 param('uint32_t', 'faceId'), param('int32_t', 'metric'),
107 ], is_const=True, is_static=True)
108 cls.add_method('AddRoute', retval('void'), [
109 param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'),
110 param('uint32_t', 'faceId'), param('int32_t', 'metric')
111 ], is_const=True, is_static=True)
112 cls.add_method('AddRoute', retval('void'), [
113 param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'),
114 param('std::shared_ptr<ns3::ndn::Face>', 'face'),
115 param('int32_t', 'metric'),
116 ], is_const=True, is_static=True)
117 cls.add_method('AddRoute', retval('void'), [
118 param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'),
119 param('ns3::Ptr<ns3::Node>', 'otherNode'),
120 param('int32_t', 'metric'),
121 ], is_const=True, is_static=True)
122 cls.add_method('AddRoute', retval('void'), [
123 param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'),
124 param('const std::string&', 'otherNodeName'),
125 param('int32_t', 'metric'),
126 ], is_const=True, is_static=True)
127 reg_fibhelper(root_module['ns3::ndn::FibHelper'])
128
129 def reg_strategychoicehelper(cls):
130 cls.add_method('Install', retval('void'), [param('ns3::Ptr<ns3::Node>', 'node'),
131 param('const const std::string&', 'name'),
132 param('const const std::string&', 'strategy')], is_const=True, is_static=True)
133 cls.add_method('Install', retval('void'), [param('const ns3::NodeContainer&', 'c'),
134 param('const const std::string&', 'name'),
135 param('const const std::string&', 'strategy')], is_const=True, is_static=True)
136 cls.add_method('InstallAll', retval('void'), [param('const std::string&', 'name'),
137 param('const std::string&', 'strategy')], is_const=True, is_static=True)
138 reg_strategychoicehelper(root_module['ns3::ndn::StrategyChoiceHelper'])
139
140 def reg_apphelper(cls):
141 cls.add_constructor([param('const std::string&', 'prefix')])
142 cls.add_method('SetPrefix', 'void', [param('const std::string&', 'prefix')])
143 cls.add_method('SetAttribute', 'void', [param('std::string', 'name'), param('const ns3::AttributeValue&', 'value')])
144 cls.add_method('Install', 'ns3::ApplicationContainer', [param('ns3::NodeContainer', 'c')])
145 cls.add_method('Install', 'ns3::ApplicationContainer', [param('ns3::Ptr<ns3::Node>', 'node')])
146 cls.add_method('Install', 'ns3::ApplicationContainer', [param('std::string', 'nodeName')])
147 reg_apphelper(root_module['ns3::ndn::AppHelper'])
148
149 def reg_GlobalRoutingHelper(cls):
150 cls.add_constructor([])
151 cls.add_method('Install', 'void', [param('ns3::Ptr<ns3::Node>', 'node')])
152 cls.add_method('Install', 'void', [param('const ns3::NodeContainer&', 'nodes')])
153 cls.add_method('InstallAll', 'void', [])
154 cls.add_method('AddOrigin', 'void', [param('const std::string&', 'prefix'), param('ns3::Ptr<ns3::Node>', 'node')])
155 cls.add_method('AddOrigin', 'void', [param('const std::string&', 'prefix'), param('const std::string&', 'nodeName')])
156 cls.add_method('AddOrigins', 'void', [param('const std::string&', 'prefix'), param('const ns3::NodeContainer&', 'nodes')])
157 cls.add_method('AddOriginsForAll', 'void', [])
Alexander Afanasyev8e60bcd2015-01-15 20:55:40 +0000158 cls.add_method('CalculateRoutes', 'void', [])
159 cls.add_method('CalculateAllPossibleRoutes', 'void', [])
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800160 reg_GlobalRoutingHelper(root_module['ns3::ndn::GlobalRoutingHelper'])
161
162 def reg_Name(root_module, cls):
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800163 cls.add_output_stream_operator()
164 for op in ['==', '!=', '<', '<=', '>', '>=']:
165 cls.add_binary_comparison_operator(op)
166 cls.add_container_traits(retval('const ns3::ndn::name::Component&'),
167 begin_method='begin', end_method='end', iterator_type='const_iterator')
168
169 cls.add_constructor([])
170 cls.add_constructor([param('const ns3::ndn::Name&', 'other')])
171 cls.add_constructor([param('const std::string&', 'url')])
172 cls.add_method('append', 'ns3::ndn::Name &', [param('const ns3::ndn::name::Component&', 'comp')])
173 cls.add_method('get', 'const ns3::ndn::name::Component&', [param('int', 'index')], is_const=True)
174 cls.add_method('getPrefix', 'ns3::ndn::Name', [param('size_t', 'len')], is_const=True)
175 cls.add_method('size', 'size_t', [], is_const=True)
176 cls.add_method('toUri', retval('std::string'), [], is_const=True)
177 reg_Name(root_module, root_module['ns3::ndn::Name'])
178
179 def reg_NameComponent(cls):
180 cls.add_output_stream_operator()
181 for op in ['==', '!=', '<', '<=', '>', '>=']:
182 cls.add_binary_comparison_operator(op)
183
184 cls.add_constructor([param('const ns3::ndn::name::Component&', 'arg0')])
185 cls.add_constructor([])
186 cls.add_method('fromNumber', 'ns3::ndn::name::Component', [param('uint64_t', 'number')])
187 cls.add_method('fromNumberWithMarker', 'ns3::ndn::name::Component', [param('uint64_t', 'number'), param('unsigned char', 'marker')])
188 cls.add_method('fromEscapedString', 'ns3::ndn::name::Component', [param('const std::string&', 'uri')])
189 reg_NameComponent(root_module['ns3::ndn::name::Component'])
190
191 def reg_Interest(cls):
192 cls.add_output_stream_operator()
193
194 cls.add_constructor([param('const ns3::ndn::Interest&', 'interest')])
195 cls.add_constructor([])
196 reg_Interest(root_module['ns3::ndn::Interest'])
197
198 def reg_Data(cls):
199 cls.add_output_stream_operator()
200
201 cls.add_constructor([param('const ns3::ndn::Data&', 'data')])
202 cls.add_constructor([])
203 reg_Data(root_module['ns3::ndn::Data'])
204
205 #########################################################################################
206 ## Interface to NFD
207 #########################################################################################
208
209 def register_L3Protocol(cls):
210 cls.add_method('getL3Protocol', 'ns3::Ptr<ns3::ndn::L3Protocol>', [param('ns3::Ptr<ns3::Object>', 'node')], is_static=True)
211 cls.add_method('getForwarder', 'std::shared_ptr<ns3::ndn::nfd::Forwarder>', [])
212 register_L3Protocol(root_module['ns3::ndn::L3Protocol'])
213
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500214 # shared_ptr<Face>
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800215 def reg_Face(cls):
216 cls.add_output_stream_operator()
217 cls.add_method('getId', retval('int64_t'), [], is_const=True)
218 reg_Face(root_module['ns3::ndn::Face'])
219
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500220 # without shared_ptr
221 def reg_nfdFace(cls):
222 cls.add_output_stream_operator()
223 cls.add_method('getId', retval('int64_t'), [], is_const=True)
224 reg_nfdFace(root_module['ns3::ndn::nfd::Face'])
225
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800226 def reg_NfdForwarder(cls):
227 cls.add_method('getFib', retval('const ns3::ndn::nfd::Fib&', caller_manages_return=False), [], is_const=True)
228 cls.add_method('getPit', retval('const ns3::ndn::nfd::Pit&', caller_manages_return=False), [], is_const=True)
229 cls.add_method('getCs', retval('const ns3::ndn::nfd::Cs&', caller_manages_return=False), [], is_const=True)
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500230 cls.add_method('getFaceTable', retval('const ns3::ndn::nfd::FaceTable&', caller_manages_return=False), [], is_const=True)
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800231 reg_NfdForwarder(root_module['ns3::ndn::nfd::Forwarder'])
232
233 #############
234 #### FIB ####
235 def reg_NfdFib(root_module, cls):
236 cls.add_method('size', retval('size_t'), [], is_const=True)
237 cls.add_container_traits(retval('const ns3::ndn::nfd::fib::Entry&', caller_manages_return=False),
238 begin_method='begin', end_method='end', iterator_type='const_iterator')
239
240 # The following is not supported
241 # cls.add_method('findLongestPrefixMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'),
242 # [param('const ns3::ndn::Name&', 'prefix')], is_const=True)
243 # cls.add_method('findExactMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'),
244 # [param('const ns3::ndn::Name&', 'prefix')], is_const=True)
245 # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'),
246 # [param('const pit::Entry&', 'pitEntry')], is_const=True)
247 # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'),
248 # [param('const measurements::Entry&', 'measurementsEntry')], is_const=True)
249
250 # cls.add_method('insert', retval('std::pair<std::shared_ptr<ns3::ndn::nfd::fib::Entry>, bool>'), [param('const ns3::ndn::Name&', 'prefix')])
251 cls.add_method('erase', retval('void'), [param('const ns3::ndn::Name&', 'prefix')])
252 cls.add_method('erase', retval('void'), [param('const ns3::ndn::nfd::fib::Entry&', 'entry')])
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800253 # cls.add_method('removeNextHopFromAllEntries', retval('void'), [param('std::shared_ptr<ns3::ndn::Face>', 'face')])
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800254
255 def reg_Entry(cls):
256 cls.add_method('getPrefix', 'const ns3::ndn::Name&', [], is_const=True)
257 cls.add_method('getNextHops', retval('const ns3::ndn::nfd::fib::NextHopList&', caller_manages_return=False), [], is_const=True)
258 cls.add_method('hasNextHops', 'bool', [], is_const=True)
259 reg_Entry(root_module['ns3::ndn::nfd::fib::Entry'])
260
261 def reg_NextHop(cls):
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500262 cls.add_constructor([param('const ns3::ndn::Face&', 'face'), param('uint64_t', 'endpointId')])
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800263
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800264 cls.add_function_as_method('getFaceFromFibNextHop', 'std::shared_ptr<ns3::ndn::Face>',
265 [param('const ns3::ndn::nfd::fib::NextHop&', 'obj')],
266 custom_name='getFace')
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800267 cls.add_method('setCost', 'void', [param('uint64_t', 'cost')])
268 cls.add_method('getCost', 'uint64_t', [], is_const=True)
269 reg_NextHop(root_module['ns3::ndn::nfd::fib::NextHop'])
270
271 def reg_NextHopList(cls):
272 cls.add_method('size', retval('size_t'), [], is_const=True)
273 cls.add_container_traits(retval('const ns3::ndn::nfd::fib::NextHop&', caller_manages_return=False),
274 begin_method='begin', end_method='end', iterator_type='const_iterator')
275 reg_NextHopList(root_module['ns3::ndn::nfd::fib::NextHopList'])
276 reg_NfdFib(root_module, root_module['ns3::ndn::nfd::Fib'])
277 #### FIB ####
278 #############
279
280 #############
281 #### PIT ####
282 def reg_NfdPit(root_module, cls):
283 cls.add_method('size', retval('size_t'), [], is_const=True)
284 cls.add_container_traits(retval('const ns3::ndn::nfd::pit::Entry&', caller_manages_return=False),
285 begin_method='begin', end_method='end', iterator_type='const_iterator')
286
287 def reg_Entry(cls):
288 cls.add_method('getInterest', retval('const ns3::ndn::Interest&'), [], is_const=True)
289 cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True)
290 reg_Entry(root_module['ns3::ndn::nfd::pit::Entry'])
291 reg_NfdPit(root_module, root_module['ns3::ndn::nfd::Pit'])
292 #### PIT ####
293 #############
294
295 #############
296 #### CS ####
297 def reg_NfdCs(root_module, cls):
298 cls.add_method('size', retval('size_t'), [], is_const=True)
299 cls.add_container_traits(retval('const ns3::ndn::nfd::cs::Entry&', caller_manages_return=False),
300 begin_method='begin', end_method='end', iterator_type='const_iterator')
301
302 def reg_Entry(cls):
303 cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True)
304 reg_Entry(root_module['ns3::ndn::nfd::cs::Entry'])
305 reg_NfdCs(root_module, root_module['ns3::ndn::nfd::Cs'])
306 #### CS ####
307 #############
308
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500309 ###################
310 #### FaceTable ####
311 def reg_NfdFaceTable(root_module, cls):
312 cls.add_method('size', retval('size_t'), [], is_const=True)
313 cls.add_container_traits(retval('const ns3::ndn::nfd::Face&', caller_manages_return=False),
314 begin_method='begin', end_method='end', iterator_type='const_iterator')
315 reg_NfdFaceTable(root_module, root_module['ns3::ndn::nfd::FaceTable'])
316 #### FaceTable ####
317 ###################
318
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800319def reg_other_modules(root_module):
320 def reg_ApplicationContainer(cls):
321 cls.add_constructor([])
322 cls.add_constructor([param('ns3::ApplicationContainer', 'container')])
323 reg_ApplicationContainer(root_module['ns3::ApplicationContainer'])
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -0700324
Alexander Afanasyev381dea02011-11-03 08:33:26 -0700325def register_functions(root_module):
Alexander Afanasyeva6cc9102013-07-15 18:44:24 -0700326 return
327
Alexander Afanasyev381dea02011-11-03 08:33:26 -0700328def main():
329 out = FileCodeSink(sys.stdout)
330 root_module = module_init()
331 register_types(root_module)
332 register_methods(root_module)
333 register_functions(root_module)
334 root_module.generate(out)
335
336if __name__ == '__main__':
337 main()