Alexander Afanasyev | 381dea0 | 2011-11-03 08:33:26 -0700 | [diff] [blame] | 1 | from pybindgen import Module, FileCodeSink, param, retval, cppclass, typehandlers |
| 2 | |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 3 | from pybindgen.typehandlers.smart_ptr import StdSharedPtr |
| 4 | |
| 5 | from ns3_ptr import Ns3PtrMemoryPolicy |
| 6 | |
Alexander Afanasyev | 381dea0 | 2011-11-03 08:33:26 -0700 | [diff] [blame] | 7 | import pybindgen.settings |
| 8 | import warnings |
| 9 | |
Alexander Afanasyev | 381dea0 | 2011-11-03 08:33:26 -0700 | [diff] [blame] | 10 | import sys |
| 11 | |
| 12 | def module_init(): |
Alexander Afanasyev | 6d98ac3 | 2012-06-06 13:01:48 -0700 | [diff] [blame] | 13 | root_module = Module('ns.ndnSIM', cpp_namespace='::ns3') |
Alexander Afanasyev | 381dea0 | 2011-11-03 08:33:26 -0700 | [diff] [blame] | 14 | return root_module |
| 15 | |
| 16 | def register_types(module): |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 17 | 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')) |
| 44 | module.add_class('FaceContainer', memory_policy=Ns3PtrMemoryPolicy('::ns3::ndn::FaceContainer')) |
| 45 | |
| 46 | def reg_name(module): |
| 47 | module.add_class('Component') |
| 48 | reg_name(module.add_cpp_namespace('name')) |
| 49 | |
| 50 | def reg_nfd(module): |
| 51 | module.add_class('Forwarder', memory_policy=StdSharedPtr('::ns3::ndn::nfd::Forwarder'), is_singleton=True) |
| 52 | module.add_class('Fib') |
| 53 | module.add_class('Pit') |
| 54 | module.add_class('Cs') |
| 55 | |
| 56 | def reg_fib(module): |
| 57 | module.add_class('Entry')#, memory_policy=StdSharedPtr('ns3::ndn::nfd::fib::Entry')) |
| 58 | module.add_class('NextHop') |
| 59 | module.add_class('NextHopList') |
| 60 | reg_fib(module.add_cpp_namespace('fib')) |
| 61 | |
| 62 | def reg_pit(module): |
| 63 | module.add_class('Entry')#, memory_policy=StdSharedPtr('ns3::ndn::nfd::pit::Entry')) |
| 64 | reg_pit(module.add_cpp_namespace('pit')) |
| 65 | |
| 66 | def reg_cs(module): |
| 67 | module.add_class('Entry')#, memory_policy=StdSharedPtr('ns3::ndn::nfd::cs::Entry')) |
| 68 | reg_cs(module.add_cpp_namespace('cs')) |
| 69 | |
| 70 | reg_nfd(module.add_cpp_namespace('nfd')) |
| 71 | reg_ndn(module.add_cpp_namespace('ndn')) |
Alexander Afanasyev | a6cc910 | 2013-07-15 18:44:24 -0700 | [diff] [blame] | 72 | |
Alexander Afanasyev | 381dea0 | 2011-11-03 08:33:26 -0700 | [diff] [blame] | 73 | def register_methods(root_module): |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 74 | reg_other_modules(root_module) |
| 75 | |
| 76 | def reg_stackhelper(cls): |
| 77 | cls.add_constructor([]) |
| 78 | |
| 79 | cls.add_method('Install', 'ns3::Ptr<ns3::ndn::FaceContainer>', [param('ns3::Ptr<ns3::Node>', 'node')], is_const=True) |
| 80 | cls.add_method('Install', 'ns3::Ptr<ns3::ndn::FaceContainer>', [param('std::string const&', 'nodeName')], is_const=True) |
| 81 | cls.add_method('Install', 'ns3::Ptr<ns3::ndn::FaceContainer>', [param('const ns3::NodeContainer&', 'c')], is_const=True) |
| 82 | cls.add_method('InstallAll', 'ns3::Ptr<ns3::ndn::FaceContainer>', [], is_const=True) |
| 83 | |
| 84 | cls.add_method('SetDefaultRoutes', retval('void'), [param('bool', 'isEnabled', default_value='true')], is_const=True) |
| 85 | cls.add_method('SetStackAttributes', |
| 86 | retval('void'), |
| 87 | [param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'), |
| 88 | param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'), |
| 89 | param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'), |
| 90 | param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')]) |
| 91 | |
| 92 | cls.add_method('setCsSize', retval('void'), [param('size_t', 'maxSize')]) |
| 93 | cls.add_method('SetOldContentStore', |
| 94 | retval('void'), |
| 95 | [param('const std::string&', 'contentStoreClass'), |
| 96 | param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'), |
| 97 | param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'), |
| 98 | param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'), |
| 99 | param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')]) |
| 100 | reg_stackhelper(root_module['ns3::ndn::StackHelper']) |
| 101 | |
| 102 | def reg_fibhelper(cls): |
| 103 | cls.add_method('AddRoute', retval('void'), [ |
| 104 | param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'), |
| 105 | param('uint32_t', 'faceId'), param('int32_t', 'metric'), |
| 106 | ], is_const=True, is_static=True) |
| 107 | cls.add_method('AddRoute', retval('void'), [ |
| 108 | param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'), |
| 109 | param('uint32_t', 'faceId'), param('int32_t', 'metric') |
| 110 | ], is_const=True, is_static=True) |
| 111 | cls.add_method('AddRoute', retval('void'), [ |
| 112 | param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'), |
| 113 | param('std::shared_ptr<ns3::ndn::Face>', 'face'), |
| 114 | param('int32_t', 'metric'), |
| 115 | ], is_const=True, is_static=True) |
| 116 | cls.add_method('AddRoute', retval('void'), [ |
| 117 | param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'), |
| 118 | param('ns3::Ptr<ns3::Node>', 'otherNode'), |
| 119 | param('int32_t', 'metric'), |
| 120 | ], is_const=True, is_static=True) |
| 121 | cls.add_method('AddRoute', retval('void'), [ |
| 122 | param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'), |
| 123 | param('const std::string&', 'otherNodeName'), |
| 124 | param('int32_t', 'metric'), |
| 125 | ], is_const=True, is_static=True) |
| 126 | reg_fibhelper(root_module['ns3::ndn::FibHelper']) |
| 127 | |
| 128 | def reg_strategychoicehelper(cls): |
| 129 | cls.add_method('Install', retval('void'), [param('ns3::Ptr<ns3::Node>', 'node'), |
| 130 | param('const const std::string&', 'name'), |
| 131 | param('const const std::string&', 'strategy')], is_const=True, is_static=True) |
| 132 | cls.add_method('Install', retval('void'), [param('const ns3::NodeContainer&', 'c'), |
| 133 | param('const const std::string&', 'name'), |
| 134 | param('const const std::string&', 'strategy')], is_const=True, is_static=True) |
| 135 | cls.add_method('InstallAll', retval('void'), [param('const std::string&', 'name'), |
| 136 | param('const std::string&', 'strategy')], is_const=True, is_static=True) |
| 137 | reg_strategychoicehelper(root_module['ns3::ndn::StrategyChoiceHelper']) |
| 138 | |
| 139 | def reg_apphelper(cls): |
| 140 | cls.add_constructor([param('const std::string&', 'prefix')]) |
| 141 | cls.add_method('SetPrefix', 'void', [param('const std::string&', 'prefix')]) |
| 142 | cls.add_method('SetAttribute', 'void', [param('std::string', 'name'), param('const ns3::AttributeValue&', 'value')]) |
| 143 | cls.add_method('Install', 'ns3::ApplicationContainer', [param('ns3::NodeContainer', 'c')]) |
| 144 | cls.add_method('Install', 'ns3::ApplicationContainer', [param('ns3::Ptr<ns3::Node>', 'node')]) |
| 145 | cls.add_method('Install', 'ns3::ApplicationContainer', [param('std::string', 'nodeName')]) |
| 146 | reg_apphelper(root_module['ns3::ndn::AppHelper']) |
| 147 | |
| 148 | def reg_GlobalRoutingHelper(cls): |
| 149 | cls.add_constructor([]) |
| 150 | cls.add_method('Install', 'void', [param('ns3::Ptr<ns3::Node>', 'node')]) |
| 151 | cls.add_method('Install', 'void', [param('const ns3::NodeContainer&', 'nodes')]) |
| 152 | cls.add_method('InstallAll', 'void', []) |
| 153 | cls.add_method('AddOrigin', 'void', [param('const std::string&', 'prefix'), param('ns3::Ptr<ns3::Node>', 'node')]) |
| 154 | cls.add_method('AddOrigin', 'void', [param('const std::string&', 'prefix'), param('const std::string&', 'nodeName')]) |
| 155 | cls.add_method('AddOrigins', 'void', [param('const std::string&', 'prefix'), param('const ns3::NodeContainer&', 'nodes')]) |
| 156 | cls.add_method('AddOriginsForAll', 'void', []) |
Alexander Afanasyev | 8e60bcd | 2015-01-15 20:55:40 +0000 | [diff] [blame] | 157 | cls.add_method('CalculateRoutes', 'void', []) |
| 158 | cls.add_method('CalculateAllPossibleRoutes', 'void', []) |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 159 | reg_GlobalRoutingHelper(root_module['ns3::ndn::GlobalRoutingHelper']) |
| 160 | |
| 161 | def reg_Name(root_module, cls): |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 162 | cls.add_output_stream_operator() |
| 163 | for op in ['==', '!=', '<', '<=', '>', '>=']: |
| 164 | cls.add_binary_comparison_operator(op) |
| 165 | cls.add_container_traits(retval('const ns3::ndn::name::Component&'), |
| 166 | begin_method='begin', end_method='end', iterator_type='const_iterator') |
| 167 | |
| 168 | cls.add_constructor([]) |
| 169 | cls.add_constructor([param('const ns3::ndn::Name&', 'other')]) |
| 170 | cls.add_constructor([param('const std::string&', 'url')]) |
| 171 | cls.add_method('append', 'ns3::ndn::Name &', [param('const ns3::ndn::name::Component&', 'comp')]) |
| 172 | cls.add_method('get', 'const ns3::ndn::name::Component&', [param('int', 'index')], is_const=True) |
| 173 | cls.add_method('getPrefix', 'ns3::ndn::Name', [param('size_t', 'len')], is_const=True) |
| 174 | cls.add_method('size', 'size_t', [], is_const=True) |
| 175 | cls.add_method('toUri', retval('std::string'), [], is_const=True) |
| 176 | reg_Name(root_module, root_module['ns3::ndn::Name']) |
| 177 | |
| 178 | def reg_NameComponent(cls): |
| 179 | cls.add_output_stream_operator() |
| 180 | for op in ['==', '!=', '<', '<=', '>', '>=']: |
| 181 | cls.add_binary_comparison_operator(op) |
| 182 | |
| 183 | cls.add_constructor([param('const ns3::ndn::name::Component&', 'arg0')]) |
| 184 | cls.add_constructor([]) |
| 185 | cls.add_method('fromNumber', 'ns3::ndn::name::Component', [param('uint64_t', 'number')]) |
| 186 | cls.add_method('fromNumberWithMarker', 'ns3::ndn::name::Component', [param('uint64_t', 'number'), param('unsigned char', 'marker')]) |
| 187 | cls.add_method('fromEscapedString', 'ns3::ndn::name::Component', [param('const std::string&', 'uri')]) |
| 188 | reg_NameComponent(root_module['ns3::ndn::name::Component']) |
| 189 | |
| 190 | def reg_Interest(cls): |
| 191 | cls.add_output_stream_operator() |
| 192 | |
| 193 | cls.add_constructor([param('const ns3::ndn::Interest&', 'interest')]) |
| 194 | cls.add_constructor([]) |
| 195 | reg_Interest(root_module['ns3::ndn::Interest']) |
| 196 | |
| 197 | def reg_Data(cls): |
| 198 | cls.add_output_stream_operator() |
| 199 | |
| 200 | cls.add_constructor([param('const ns3::ndn::Data&', 'data')]) |
| 201 | cls.add_constructor([]) |
| 202 | reg_Data(root_module['ns3::ndn::Data']) |
| 203 | |
| 204 | ######################################################################################### |
| 205 | ## Interface to NFD |
| 206 | ######################################################################################### |
| 207 | |
| 208 | def register_L3Protocol(cls): |
| 209 | cls.add_method('getL3Protocol', 'ns3::Ptr<ns3::ndn::L3Protocol>', [param('ns3::Ptr<ns3::Object>', 'node')], is_static=True) |
| 210 | cls.add_method('getForwarder', 'std::shared_ptr<ns3::ndn::nfd::Forwarder>', []) |
| 211 | register_L3Protocol(root_module['ns3::ndn::L3Protocol']) |
| 212 | |
| 213 | def reg_Face(cls): |
| 214 | cls.add_output_stream_operator() |
| 215 | cls.add_method('getId', retval('int64_t'), [], is_const=True) |
| 216 | reg_Face(root_module['ns3::ndn::Face']) |
| 217 | |
| 218 | def reg_NfdForwarder(cls): |
| 219 | cls.add_method('getFib', retval('const ns3::ndn::nfd::Fib&', caller_manages_return=False), [], is_const=True) |
| 220 | cls.add_method('getPit', retval('const ns3::ndn::nfd::Pit&', caller_manages_return=False), [], is_const=True) |
| 221 | cls.add_method('getCs', retval('const ns3::ndn::nfd::Cs&', caller_manages_return=False), [], is_const=True) |
| 222 | reg_NfdForwarder(root_module['ns3::ndn::nfd::Forwarder']) |
| 223 | |
| 224 | ############# |
| 225 | #### FIB #### |
| 226 | def reg_NfdFib(root_module, cls): |
| 227 | cls.add_method('size', retval('size_t'), [], is_const=True) |
| 228 | cls.add_container_traits(retval('const ns3::ndn::nfd::fib::Entry&', caller_manages_return=False), |
| 229 | begin_method='begin', end_method='end', iterator_type='const_iterator') |
| 230 | |
| 231 | # The following is not supported |
| 232 | # cls.add_method('findLongestPrefixMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'), |
| 233 | # [param('const ns3::ndn::Name&', 'prefix')], is_const=True) |
| 234 | # cls.add_method('findExactMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'), |
| 235 | # [param('const ns3::ndn::Name&', 'prefix')], is_const=True) |
| 236 | # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'), |
| 237 | # [param('const pit::Entry&', 'pitEntry')], is_const=True) |
| 238 | # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'), |
| 239 | # [param('const measurements::Entry&', 'measurementsEntry')], is_const=True) |
| 240 | |
| 241 | # cls.add_method('insert', retval('std::pair<std::shared_ptr<ns3::ndn::nfd::fib::Entry>, bool>'), [param('const ns3::ndn::Name&', 'prefix')]) |
| 242 | cls.add_method('erase', retval('void'), [param('const ns3::ndn::Name&', 'prefix')]) |
| 243 | cls.add_method('erase', retval('void'), [param('const ns3::ndn::nfd::fib::Entry&', 'entry')]) |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 244 | # cls.add_method('removeNextHopFromAllEntries', retval('void'), [param('std::shared_ptr<ns3::ndn::Face>', 'face')]) |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 245 | |
| 246 | def reg_Entry(cls): |
| 247 | cls.add_method('getPrefix', 'const ns3::ndn::Name&', [], is_const=True) |
| 248 | cls.add_method('getNextHops', retval('const ns3::ndn::nfd::fib::NextHopList&', caller_manages_return=False), [], is_const=True) |
| 249 | cls.add_method('hasNextHops', 'bool', [], is_const=True) |
| 250 | reg_Entry(root_module['ns3::ndn::nfd::fib::Entry']) |
| 251 | |
| 252 | def reg_NextHop(cls): |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 253 | cls.add_constructor([param('const ns3::ndn::Face&', 'face')]) |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 254 | |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 255 | cls.add_function_as_method('getFaceFromFibNextHop', 'std::shared_ptr<ns3::ndn::Face>', |
| 256 | [param('const ns3::ndn::nfd::fib::NextHop&', 'obj')], |
| 257 | custom_name='getFace') |
Alexander Afanasyev | 5713e7a | 2015-01-02 01:08:18 -0800 | [diff] [blame] | 258 | cls.add_method('setCost', 'void', [param('uint64_t', 'cost')]) |
| 259 | cls.add_method('getCost', 'uint64_t', [], is_const=True) |
| 260 | reg_NextHop(root_module['ns3::ndn::nfd::fib::NextHop']) |
| 261 | |
| 262 | def reg_NextHopList(cls): |
| 263 | cls.add_method('size', retval('size_t'), [], is_const=True) |
| 264 | cls.add_container_traits(retval('const ns3::ndn::nfd::fib::NextHop&', caller_manages_return=False), |
| 265 | begin_method='begin', end_method='end', iterator_type='const_iterator') |
| 266 | reg_NextHopList(root_module['ns3::ndn::nfd::fib::NextHopList']) |
| 267 | reg_NfdFib(root_module, root_module['ns3::ndn::nfd::Fib']) |
| 268 | #### FIB #### |
| 269 | ############# |
| 270 | |
| 271 | ############# |
| 272 | #### PIT #### |
| 273 | def reg_NfdPit(root_module, cls): |
| 274 | cls.add_method('size', retval('size_t'), [], is_const=True) |
| 275 | cls.add_container_traits(retval('const ns3::ndn::nfd::pit::Entry&', caller_manages_return=False), |
| 276 | begin_method='begin', end_method='end', iterator_type='const_iterator') |
| 277 | |
| 278 | def reg_Entry(cls): |
| 279 | cls.add_method('getInterest', retval('const ns3::ndn::Interest&'), [], is_const=True) |
| 280 | cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True) |
| 281 | reg_Entry(root_module['ns3::ndn::nfd::pit::Entry']) |
| 282 | reg_NfdPit(root_module, root_module['ns3::ndn::nfd::Pit']) |
| 283 | #### PIT #### |
| 284 | ############# |
| 285 | |
| 286 | ############# |
| 287 | #### CS #### |
| 288 | def reg_NfdCs(root_module, cls): |
| 289 | cls.add_method('size', retval('size_t'), [], is_const=True) |
| 290 | cls.add_container_traits(retval('const ns3::ndn::nfd::cs::Entry&', caller_manages_return=False), |
| 291 | begin_method='begin', end_method='end', iterator_type='const_iterator') |
| 292 | |
| 293 | def reg_Entry(cls): |
| 294 | cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True) |
| 295 | reg_Entry(root_module['ns3::ndn::nfd::cs::Entry']) |
| 296 | reg_NfdCs(root_module, root_module['ns3::ndn::nfd::Cs']) |
| 297 | #### CS #### |
| 298 | ############# |
| 299 | |
| 300 | def reg_other_modules(root_module): |
| 301 | def reg_ApplicationContainer(cls): |
| 302 | cls.add_constructor([]) |
| 303 | cls.add_constructor([param('ns3::ApplicationContainer', 'container')]) |
| 304 | reg_ApplicationContainer(root_module['ns3::ApplicationContainer']) |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 305 | |
Alexander Afanasyev | 381dea0 | 2011-11-03 08:33:26 -0700 | [diff] [blame] | 306 | def register_functions(root_module): |
Alexander Afanasyev | a6cc910 | 2013-07-15 18:44:24 -0700 | [diff] [blame] | 307 | return |
| 308 | |
Alexander Afanasyev | 381dea0 | 2011-11-03 08:33:26 -0700 | [diff] [blame] | 309 | def main(): |
| 310 | out = FileCodeSink(sys.stdout) |
| 311 | root_module = module_init() |
| 312 | register_types(root_module) |
| 313 | register_methods(root_module) |
| 314 | register_functions(root_module) |
| 315 | root_module.generate(out) |
| 316 | |
| 317 | if __name__ == '__main__': |
| 318 | main() |