weird error when including internet-module.h

381 views
Skip to first unread message

vahid Saber

unread,
Aug 6, 2013, 1:12:41 AM8/6/13
to ns-3-...@googlegroups.com
Hi all,
I develop my model inside the /src/myModel/model sub-directory.

I have just created a class that requires a member of type "Ipv4AddressHelper" .

Naturally, I should have included "ns3/internet-module.h" in my header file, right?

but I got a lot of unfamiliar errors coming from ./ns3/ipv4-header.h (shown below).

may I know where I have made a mistake please?

p.s. : I also tried to link 'internet' but it didn't change anything(did I have to add anything else?)

I appreciate your kind help. Thie is the error

In file included from ./ns3/ip-l4-protocol.h:29:0,
                 from ./ns3/ipv4.h:27,
                 from ./ns3/ipv4-interface-container.h:6,
                 from ./ns3/ipv4-address-helper.h:24,
                 from ./ns3/smb_base_ip.h:17,
                 from ./ns3/simmobility-module.h:14,
                 from ../src/simmobility/examples/simmobility-example.cc:13:
./ns3/ipv4-header.h:88:7: error: expected identifier before numeric constant
./ns3/ipv4-header.h:88:7: error: expected ‘}’ before numeric constant
./ns3/ipv4-header.h:88:7: error: expected unqualified-id before numeric constant
./ns3/ipv4-header.h:99:17: error: variable or field ‘SetDscp’ declared void
./ns3/ipv4-header.h:99:17: error: ‘DscpType’ was not declared in this scope
./ns3/ipv4-header.h:159:34: error: non-member function ‘uint16_t ns3::GetPayloadSize()’ cannot have cv-qualifier
./ns3/ipv4-header.h:163:37: error: non-member function ‘uint16_t ns3::GetIdentification()’ cannot have cv-qualifier
./ns3/ipv4-header.h:167:25: error: non-member function ‘uint8_t ns3::GetTos()’ cannot have cv-qualifier
./ns3/ipv4-header.h:171:3: error: ‘DscpType’ does not name a type
./ns3/ipv4-header.h:175:33: error: ‘DscpType’ was not declared in this scope
./ns3/ipv4-header.h:175:48: error: expected ‘,’ or ‘;’ before ‘const’
./ns3/ipv4-header.h:179:25: error: non-member function ‘ns3::EcnType ns3::GetEcn()’ cannot have cv-qualifier
./ns3/ipv4-header.h:183:45: error: non-member function ‘std::string ns3::EcnTypeToString(ns3::EcnType)’ cannot have cv-qualifier
./ns3/ipv4-header.h:187:30: error: non-member function ‘bool ns3::IsLastFragment()’ cannot have cv-qualifier
./ns3/ipv4-header.h:191:30: error: non-member function ‘bool ns3::IsDontFragment()’ cannot have cv-qualifier
./ns3/ipv4-header.h:195:37: error: non-member function ‘uint16_t ns3::GetFragmentOffset()’ cannot have cv-qualifier
./ns3/ipv4-header.h:199:25: error: non-member function ‘uint8_t ns3::GetTtl()’ cannot have cv-qualifier
./ns3/ipv4-header.h:203:30: error: non-member function ‘uint8_t ns3::GetProtocol()’ cannot have cv-qualifier
./ns3/ipv4-header.h:207:32: error: non-member function ‘ns3::Ipv4Address ns3::GetSource()’ cannot have cv-qualifier
./ns3/ipv4-header.h:211:37: error: non-member function ‘ns3::Ipv4Address ns3::GetDestination()’ cannot have cv-qualifier
./ns3/ipv4-header.h:219:28: error: non-member function ‘bool ns3::IsChecksumOk()’ cannot have cv-qualifier
./ns3/ipv4-header.h:222:43: error: ‘virtual’ outside class declaration
./ns3/ipv4-header.h:222:43: error: non-member function ‘ns3::TypeId ns3::GetInstanceTypeId()’ cannot have cv-qualifier
./ns3/ipv4-header.h:223:41: error: ‘virtual’ outside class declaration
./ns3/ipv4-header.h:223:41: error: non-member function ‘void ns3::Print(std::ostream&)’ cannot have cv-qualifier
./ns3/ipv4-header.h:224:45: error: ‘virtual’ outside class declaration
./ns3/ipv4-header.h:224:45: error: non-member function ‘uint32_t ns3::GetSerializedSize()’ cannot have cv-qualifier
./ns3/ipv4-header.h:225:51: error: ‘virtual’ outside class declaration
./ns3/ipv4-header.h:225:51: error: non-member function ‘void ns3::Serialize(ns3::Buffer::Iterator)’ cannot have cv-qualifier
./ns3/ipv4-header.h:226:55: error: ‘virtual’ outside class declaration
./ns3/ipv4-header.h:227:1: error: expected unqualified-id before ‘private’
./ns3/ipv4-header.h:238:18: error: expected initializer before ‘:’ token
./ns3/ipv4-header.h:239:18: error: expected initializer before ‘:’ token
./ns3/ipv4-header.h:240:23: error: expected initializer before ‘:’ token
./ns3/ipv4-header.h:241:20: error: expected initializer before ‘:’ token
./ns3/ipv4-header.h:250:1: error: expected declaration before ‘}’ token
./ns3/ipv4-header.h:221:17: error: ‘ns3::TypeId ns3::GetTypeId()’ declared ‘static’ but never defined [-Werror=unused-function]


thank you for your help



Konstantinos

unread,
Aug 6, 2013, 4:45:02 AM8/6/13
to ns-3-...@googlegroups.com
Hi,

When creating a new module and require some headers from other modules, it is advised to use only those headers required (not the module header).

In addition, you should properly configure the wscript file in order to add the dependency on that module.

Regards,
K.

vahid Saber

unread,
Aug 6, 2013, 5:37:24 AM8/6/13
to ns-3-...@googlegroups.com
Thanks for your reply.
I tried to do what you advised but....
initially, let's not talk about model. First I want to know what I CAN do and then what I SHOULD do.
let's create the following files only! 
1- src/test1/examples/test1.cc :

#include "ns3/core-module.h"
//#include "ns3/internet-module.h"
//#include "ns3/internet-stack-helper.h"
//#include "ns3/ipv4-address-helper.h"

using namespace ns3;

int main() {
//...
Simulator::Run();
Simulator::Destroy();
}

2-src/test1/examples/wscript:
def build(bld):
    obj = bld.create_ns3_program('test1-example',['core', 'internet'])
    obj.source = 'test1.cc'

3- build should complete successfully. so the first question CAN I do this?  SOULD I do this way?

4-Now uncomment any of the headers in the test1.cc . they will generate the same error and I don't know what I put in the wscript other than 'internet'

I appreciate your help.
thanks


--
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/EmMng9OWifA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+...@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Konstantinos

unread,
Aug 6, 2013, 5:51:45 AM8/6/13
to ns-3-...@googlegroups.com

On Tuesday, August 6, 2013 10:37:24 AM UTC+1, vahid Saber wrote:
Thanks for your reply.
I tried to do what you advised but....
initially, let's not talk about model. First I want to know what I CAN do and then what I SHOULD do.
let's create the following files only! 
1- src/test1/examples/test1.cc :

#include "ns3/core-module.h"
//#include "ns3/internet-module.h"
//#include "ns3/internet-stack-helper.h"
//#include "ns3/ipv4-address-helper.h"

using namespace ns3;

int main() {
//...
Simulator::Run();
Simulator::Destroy();
}

2-src/test1/examples/wscript:
def build(bld):
    obj = bld.create_ns3_program('test1-example',['core', 'internet'])
    obj.source = 'test1.cc'

3- build should complete successfully. so the first question CAN I do this?  SOULD I do this way?

Yes, you can do it. And since this is an 'example' script and not a module file, it's ok using the module header and not the exact header file.
 

4-Now uncomment any of the headers in the test1.cc . they will generate the same error and I don't know what I put in the wscript other than 'internet'


After creating your 'test1' module and more specifically every time you change something in the wscript file, you should re-configure NS-3, so that the changes in the wscript are in effect.

./waf clean
./waf configure (perhaps you want to enable the examples here)
./waf build

vahid Saber

unread,
Aug 6, 2013, 6:07:00 AM8/6/13
to ns-3-...@googlegroups.com
Oh! it worked.
Thanks a lot !
Let's go to the module discussion:
when you somewhat advised me to use the specific header, then do I have to change the linking module in the wscript file also?
more specifically, suppose I use ipv4-header.h instead of internet-module.h , then what should I replace 'internet' with? (in the wscript file)
thanks again



Konstantinos

unread,
Aug 6, 2013, 6:16:45 AM8/6/13
to ns-3-...@googlegroups.com
No, you do not have to change anything in the wscript. The wscript file only check the dependencies and if for example there is a change in the internet module, then it will re-build your module too.

If I'm not mistaken, if you try to use the 'internet-module.h' inside your model files, the compiler will complain and tell you not to use it. 

vahid Saber

unread,
Aug 6, 2013, 6:22:34 AM8/6/13
to ns-3-...@googlegroups.com
On Tue, Aug 6, 2013 at 6:16 PM, Konstantinos <dinos.k...@gmail.com> wrote:
No, you do not have to change anything in the wscript. The wscript file only check the dependencies and if for example there is a change in the internet module, then it will re-build your module too.
OK, Noted 

If I'm not mistaken, if you try to use the 'internet-module.h' inside your model files, the compiler will complain and tell you not to use it. 
I just tried it. Seems there is no complain

Thanks Konstantinos. you just saved me a lot of time.

vahid Saber

unread,
Aug 19, 2013, 3:36:57 AM8/19/13
to ns-3-...@googlegroups.com
Hi Again,
I thought I was done with this problem but I wasn't.
Although you had given me a couple of good advice on coding and compilation tips, the problem was something else that wasn't reflected in the code I posted. I found the problem but dont have a real solution for it:
in my script file my inclusion looks like this:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/my-module.h"

#include <boost/asio.hpp>
#include <boost/array.hpp>

#include <iostream>
#include <string>

If I just move the boost header to above the ns3 libraries(like below), the problem will occur again:

#include <boost/asio.hpp>
#include <boost/array.hpp>

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/my-module.h"

#include <iostream>
#include <string>


I am afraid that someone else might get stuck in this and waste many days and putting a lot of futile effort solving this, or similar problems can catch my neck later.

Any good advice on why this problem can probably occur? what is a good practice- in general- to avoid this?

thank you very much

vahid

Reply all
Reply to author
Forward
0 new messages