tamuct ccilab
tamuct ccilab

Reputation: 1

NS-3 Python simulation

I'm trying to work with ns-3 in python. I am specifically working on the manet-routing-compare.cc file in the example directory, and trying to convert it into Python code.

In manet-routing-compare.cc, line 379:

AddressValue remoteAddress(InetSocketAddress(adhocInterfaces.GetAddress(i), port));

I converted it to:

port = c_int(9)
remoteAddress = ns.network.AddressValue(ns.network.InetSocketAddress(adhocInterfaces.GetAddress(i), port.value))

But I got the following error:

TypeError: none of the 4 overloaded methods succeeded. Full details:
  AddressValue::AddressValue(ns3::AddressValue&&) =>
    ValueError: could not convert argument 1 (object is not an rvalue)
  AddressValue::AddressValue(const ns3::AddressValue&) =>
    TypeError: could not convert argument 1
  AddressValue::AddressValue() =>
    TypeError: takes at most 0 arguments (1 given)
  AddressValue::AddressValue(const ns3::Address& value) =>
    TypeError: could not convert argument 1

Any suggestions for solving this problem?

The following statement prints this:

print(ns.network.InetSocketAddress(adhocInterfaces.GetAddress(i), port.value))
02-07-0a:01:01:01:09:00:00

Upvotes: 0

Views: 147

Answers (1)

Gabriel
Gabriel

Reputation: 136

Like responded on the ns-3-users forums, this is due to a Cppyy limitation that doesn't support a custom operator Address, requiring explicit conversion from the InetSocketAddress type to Address.

The conversion can be done via InetSocketAddress().ConvertTo() in ns-3.38 and onwards, or ns.addressFromInetSocketAddress(InetSocketAddress()) in ns-3.37.

Link to forum posts https://groups.google.com/g/ns-3-users/c/yQ3h_y235Es

Upvotes: 0

Related Questions