blob: 791a3bcf92511ac6a8a88c19566af46265084902 [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')])
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -080094 reg_stackhelper(root_module['ns3::ndn::StackHelper'])
95
96 def reg_fibhelper(cls):
97 cls.add_method('AddRoute', retval('void'), [
98 param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'),
99 param('uint32_t', 'faceId'), param('int32_t', 'metric'),
100 ], is_const=True, is_static=True)
101 cls.add_method('AddRoute', retval('void'), [
102 param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'),
103 param('uint32_t', 'faceId'), param('int32_t', 'metric')
104 ], is_const=True, is_static=True)
105 cls.add_method('AddRoute', retval('void'), [
106 param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'),
107 param('std::shared_ptr<ns3::ndn::Face>', 'face'),
108 param('int32_t', 'metric'),
109 ], is_const=True, is_static=True)
110 cls.add_method('AddRoute', retval('void'), [
111 param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'),
112 param('ns3::Ptr<ns3::Node>', 'otherNode'),
113 param('int32_t', 'metric'),
114 ], is_const=True, is_static=True)
115 cls.add_method('AddRoute', retval('void'), [
116 param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'),
117 param('const std::string&', 'otherNodeName'),
118 param('int32_t', 'metric'),
119 ], is_const=True, is_static=True)
120 reg_fibhelper(root_module['ns3::ndn::FibHelper'])
121
122 def reg_strategychoicehelper(cls):
123 cls.add_method('Install', retval('void'), [param('ns3::Ptr<ns3::Node>', 'node'),
124 param('const const std::string&', 'name'),
125 param('const const std::string&', 'strategy')], is_const=True, is_static=True)
126 cls.add_method('Install', retval('void'), [param('const ns3::NodeContainer&', 'c'),
127 param('const const std::string&', 'name'),
128 param('const const std::string&', 'strategy')], is_const=True, is_static=True)
129 cls.add_method('InstallAll', retval('void'), [param('const std::string&', 'name'),
130 param('const std::string&', 'strategy')], is_const=True, is_static=True)
131 reg_strategychoicehelper(root_module['ns3::ndn::StrategyChoiceHelper'])
132
133 def reg_apphelper(cls):
134 cls.add_constructor([param('const std::string&', 'prefix')])
135 cls.add_method('SetPrefix', 'void', [param('const std::string&', 'prefix')])
136 cls.add_method('SetAttribute', 'void', [param('std::string', 'name'), param('const ns3::AttributeValue&', 'value')])
137 cls.add_method('Install', 'ns3::ApplicationContainer', [param('ns3::NodeContainer', 'c')])
138 cls.add_method('Install', 'ns3::ApplicationContainer', [param('ns3::Ptr<ns3::Node>', 'node')])
139 cls.add_method('Install', 'ns3::ApplicationContainer', [param('std::string', 'nodeName')])
140 reg_apphelper(root_module['ns3::ndn::AppHelper'])
141
142 def reg_GlobalRoutingHelper(cls):
143 cls.add_constructor([])
144 cls.add_method('Install', 'void', [param('ns3::Ptr<ns3::Node>', 'node')])
145 cls.add_method('Install', 'void', [param('const ns3::NodeContainer&', 'nodes')])
146 cls.add_method('InstallAll', 'void', [])
147 cls.add_method('AddOrigin', 'void', [param('const std::string&', 'prefix'), param('ns3::Ptr<ns3::Node>', 'node')])
148 cls.add_method('AddOrigin', 'void', [param('const std::string&', 'prefix'), param('const std::string&', 'nodeName')])
149 cls.add_method('AddOrigins', 'void', [param('const std::string&', 'prefix'), param('const ns3::NodeContainer&', 'nodes')])
150 cls.add_method('AddOriginsForAll', 'void', [])
Alexander Afanasyev8e60bcd2015-01-15 20:55:40 +0000151 cls.add_method('CalculateRoutes', 'void', [])
152 cls.add_method('CalculateAllPossibleRoutes', 'void', [])
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800153 reg_GlobalRoutingHelper(root_module['ns3::ndn::GlobalRoutingHelper'])
154
155 def reg_Name(root_module, cls):
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800156 cls.add_output_stream_operator()
157 for op in ['==', '!=', '<', '<=', '>', '>=']:
158 cls.add_binary_comparison_operator(op)
159 cls.add_container_traits(retval('const ns3::ndn::name::Component&'),
160 begin_method='begin', end_method='end', iterator_type='const_iterator')
161
162 cls.add_constructor([])
163 cls.add_constructor([param('const ns3::ndn::Name&', 'other')])
164 cls.add_constructor([param('const std::string&', 'url')])
165 cls.add_method('append', 'ns3::ndn::Name &', [param('const ns3::ndn::name::Component&', 'comp')])
166 cls.add_method('get', 'const ns3::ndn::name::Component&', [param('int', 'index')], is_const=True)
167 cls.add_method('getPrefix', 'ns3::ndn::Name', [param('size_t', 'len')], is_const=True)
168 cls.add_method('size', 'size_t', [], is_const=True)
169 cls.add_method('toUri', retval('std::string'), [], is_const=True)
170 reg_Name(root_module, root_module['ns3::ndn::Name'])
171
172 def reg_NameComponent(cls):
173 cls.add_output_stream_operator()
174 for op in ['==', '!=', '<', '<=', '>', '>=']:
175 cls.add_binary_comparison_operator(op)
176
177 cls.add_constructor([param('const ns3::ndn::name::Component&', 'arg0')])
178 cls.add_constructor([])
179 cls.add_method('fromNumber', 'ns3::ndn::name::Component', [param('uint64_t', 'number')])
180 cls.add_method('fromNumberWithMarker', 'ns3::ndn::name::Component', [param('uint64_t', 'number'), param('unsigned char', 'marker')])
181 cls.add_method('fromEscapedString', 'ns3::ndn::name::Component', [param('const std::string&', 'uri')])
182 reg_NameComponent(root_module['ns3::ndn::name::Component'])
183
184 def reg_Interest(cls):
185 cls.add_output_stream_operator()
186
187 cls.add_constructor([param('const ns3::ndn::Interest&', 'interest')])
188 cls.add_constructor([])
189 reg_Interest(root_module['ns3::ndn::Interest'])
190
191 def reg_Data(cls):
192 cls.add_output_stream_operator()
193
194 cls.add_constructor([param('const ns3::ndn::Data&', 'data')])
195 cls.add_constructor([])
196 reg_Data(root_module['ns3::ndn::Data'])
197
198 #########################################################################################
199 ## Interface to NFD
200 #########################################################################################
201
202 def register_L3Protocol(cls):
203 cls.add_method('getL3Protocol', 'ns3::Ptr<ns3::ndn::L3Protocol>', [param('ns3::Ptr<ns3::Object>', 'node')], is_static=True)
204 cls.add_method('getForwarder', 'std::shared_ptr<ns3::ndn::nfd::Forwarder>', [])
205 register_L3Protocol(root_module['ns3::ndn::L3Protocol'])
206
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500207 # shared_ptr<Face>
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800208 def reg_Face(cls):
209 cls.add_output_stream_operator()
210 cls.add_method('getId', retval('int64_t'), [], is_const=True)
211 reg_Face(root_module['ns3::ndn::Face'])
212
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500213 # without shared_ptr
214 def reg_nfdFace(cls):
215 cls.add_output_stream_operator()
216 cls.add_method('getId', retval('int64_t'), [], is_const=True)
217 reg_nfdFace(root_module['ns3::ndn::nfd::Face'])
218
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800219 def reg_NfdForwarder(cls):
220 cls.add_method('getFib', retval('const ns3::ndn::nfd::Fib&', caller_manages_return=False), [], is_const=True)
221 cls.add_method('getPit', retval('const ns3::ndn::nfd::Pit&', caller_manages_return=False), [], is_const=True)
222 cls.add_method('getCs', retval('const ns3::ndn::nfd::Cs&', caller_manages_return=False), [], is_const=True)
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500223 cls.add_method('getFaceTable', retval('const ns3::ndn::nfd::FaceTable&', caller_manages_return=False), [], is_const=True)
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800224 reg_NfdForwarder(root_module['ns3::ndn::nfd::Forwarder'])
225
226 #############
227 #### FIB ####
228 def reg_NfdFib(root_module, cls):
229 cls.add_method('size', retval('size_t'), [], is_const=True)
230 cls.add_container_traits(retval('const ns3::ndn::nfd::fib::Entry&', caller_manages_return=False),
231 begin_method='begin', end_method='end', iterator_type='const_iterator')
232
233 # The following is not supported
234 # cls.add_method('findLongestPrefixMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'),
235 # [param('const ns3::ndn::Name&', 'prefix')], is_const=True)
236 # cls.add_method('findExactMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'),
237 # [param('const ns3::ndn::Name&', 'prefix')], is_const=True)
238 # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'),
239 # [param('const pit::Entry&', 'pitEntry')], is_const=True)
240 # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'),
241 # [param('const measurements::Entry&', 'measurementsEntry')], is_const=True)
242
243 # cls.add_method('insert', retval('std::pair<std::shared_ptr<ns3::ndn::nfd::fib::Entry>, bool>'), [param('const ns3::ndn::Name&', 'prefix')])
244 cls.add_method('erase', retval('void'), [param('const ns3::ndn::Name&', 'prefix')])
245 cls.add_method('erase', retval('void'), [param('const ns3::ndn::nfd::fib::Entry&', 'entry')])
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800246 # cls.add_method('removeNextHopFromAllEntries', retval('void'), [param('std::shared_ptr<ns3::ndn::Face>', 'face')])
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800247
248 def reg_Entry(cls):
249 cls.add_method('getPrefix', 'const ns3::ndn::Name&', [], is_const=True)
250 cls.add_method('getNextHops', retval('const ns3::ndn::nfd::fib::NextHopList&', caller_manages_return=False), [], is_const=True)
251 cls.add_method('hasNextHops', 'bool', [], is_const=True)
252 reg_Entry(root_module['ns3::ndn::nfd::fib::Entry'])
253
254 def reg_NextHop(cls):
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500255 cls.add_constructor([param('const ns3::ndn::Face&', 'face'), param('uint64_t', 'endpointId')])
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800256
Spyridon Mastorakisb0b22412016-12-07 14:33:46 -0800257 cls.add_function_as_method('getFaceFromFibNextHop', 'std::shared_ptr<ns3::ndn::Face>',
258 [param('const ns3::ndn::nfd::fib::NextHop&', 'obj')],
259 custom_name='getFace')
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800260 cls.add_method('setCost', 'void', [param('uint64_t', 'cost')])
261 cls.add_method('getCost', 'uint64_t', [], is_const=True)
262 reg_NextHop(root_module['ns3::ndn::nfd::fib::NextHop'])
263
264 def reg_NextHopList(cls):
265 cls.add_method('size', retval('size_t'), [], is_const=True)
266 cls.add_container_traits(retval('const ns3::ndn::nfd::fib::NextHop&', caller_manages_return=False),
267 begin_method='begin', end_method='end', iterator_type='const_iterator')
268 reg_NextHopList(root_module['ns3::ndn::nfd::fib::NextHopList'])
269 reg_NfdFib(root_module, root_module['ns3::ndn::nfd::Fib'])
270 #### FIB ####
271 #############
272
273 #############
274 #### PIT ####
275 def reg_NfdPit(root_module, cls):
276 cls.add_method('size', retval('size_t'), [], is_const=True)
277 cls.add_container_traits(retval('const ns3::ndn::nfd::pit::Entry&', caller_manages_return=False),
278 begin_method='begin', end_method='end', iterator_type='const_iterator')
279
280 def reg_Entry(cls):
281 cls.add_method('getInterest', retval('const ns3::ndn::Interest&'), [], is_const=True)
282 cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True)
283 reg_Entry(root_module['ns3::ndn::nfd::pit::Entry'])
284 reg_NfdPit(root_module, root_module['ns3::ndn::nfd::Pit'])
285 #### PIT ####
286 #############
287
288 #############
289 #### CS ####
290 def reg_NfdCs(root_module, cls):
291 cls.add_method('size', retval('size_t'), [], is_const=True)
292 cls.add_container_traits(retval('const ns3::ndn::nfd::cs::Entry&', caller_manages_return=False),
293 begin_method='begin', end_method='end', iterator_type='const_iterator')
294
295 def reg_Entry(cls):
296 cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True)
297 reg_Entry(root_module['ns3::ndn::nfd::cs::Entry'])
298 reg_NfdCs(root_module, root_module['ns3::ndn::nfd::Cs'])
299 #### CS ####
300 #############
301
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500302 ###################
303 #### FaceTable ####
304 def reg_NfdFaceTable(root_module, cls):
305 cls.add_method('size', retval('size_t'), [], is_const=True)
306 cls.add_container_traits(retval('const ns3::ndn::nfd::Face&', caller_manages_return=False),
307 begin_method='begin', end_method='end', iterator_type='const_iterator')
308 reg_NfdFaceTable(root_module, root_module['ns3::ndn::nfd::FaceTable'])
309 #### FaceTable ####
310 ###################
311
Alexander Afanasyev5713e7a2015-01-02 01:08:18 -0800312def reg_other_modules(root_module):
313 def reg_ApplicationContainer(cls):
314 cls.add_constructor([])
315 cls.add_constructor([param('ns3::ApplicationContainer', 'container')])
316 reg_ApplicationContainer(root_module['ns3::ApplicationContainer'])
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -0700317
Alexander Afanasyev381dea02011-11-03 08:33:26 -0700318def register_functions(root_module):
Alexander Afanasyeva6cc9102013-07-15 18:44:24 -0700319 return
320
Alexander Afanasyev381dea02011-11-03 08:33:26 -0700321def main():
322 out = FileCodeSink(sys.stdout)
323 root_module = module_init()
324 register_types(root_module)
325 register_methods(root_module)
326 register_functions(root_module)
327 root_module.generate(out)
328
329if __name__ == '__main__':
330 main()