Hello everyone. My name is Emanuele, and i am an university student from
Rome. I have a weird bug involving the INET framework and i hope
some
of you can help me with it. I need to use an extended version of the
inet::tcp::TCPSegment class for a project, but i seem to miss some steps
of the
process because all i get is a crash. ( i get no compilation error by the way )
The crash appens in a client<-->router<-->server very basic network. More precisely, the crash occours when the client tries to connect the server ( so the crash is not right at the start ).
Here are the steps of my code:
I have a TCP2 class that extends from TCP. I have a TCP2.ned file that is used as transport protocol in a StandardHost module.
Here i explain my c++ code. ( i will omit all the #includes)
/// header file
namespace inet{
namespace tcp{
class TCP2: public TCP {
protected:
/// Override of the TCPConnection class factory
TCPConnection *createConnection(int appGateIndex, int connId) override;
};
} /// end of tcp namespace
} /// end of inet namespace
/// surce file
namespace inet{
namespace tcp{
...
Define_Module(TCP2);
...
TCPConnection *TCP2
::createConnection(int appGateIndex, int connId)
{
/// return my custom connection class ( constructor is identical to super's one)
return new TCPConnection2(this, appGateIndex, connId);
};
} /// end of tcp namespace
} /// end of inet namespace
The reason i override the createConnection
function is because i need to use an edited version of TCPConnection
class, i called it TCPConnection2:
/// header file
namespace inet{
namespace tcp{
class TCPConnection2: public TCPConnection {
public:
/// Call contructor and super constructor
XCPConnection(TCP *_mod, int _appGateIndex, int _connId) :
// inheritance constructor queue
TCPConnection(_mod, _appGateIndex, _connId){}
/// used to return an edited TCP segment
virtual TCPSegment *createTCPSegment(const char *name) override;
};
} /// end of tcp namespace
} /// end of inet namespace
/// surce file
namespace inet{
namespace tcp{
TCPSegment *
TCPConnection2
::
createTCPSegment
(const char * name)
{
/// TCPSegment2 extends
TCPSegment
return new TCPSegment2(name);
};
} /// end of tcp namespace
} /// end of inet namespace
This is clearly used to createTCPSegment2 instances, instead of the stdandard ones:
/// header file
namespace inet{
namespace tcp{
class TCPSegment2 : public TCPSegment
{
public:
TCPSegment2(const char * name, int kind = 0) :
TCPSegment(name, kind){}
... here i added some fields with getters and setters, nothing more ...
}
} /// end of tcp namespace
} /// end of inet namespace
The source file of TCPSegment2 just contains some getters and setters
for the fields i added to the class, so i will avoid writing it.
Since i experienced the bug, i restored the code of
TCPConnection2
::
createTCPSegment
to the original one, for debug porpouse.
Let me be super clear about this:I didnt erease the override function in my
TCPConnection2
class. My override function still appears in the source file, but the
code is the exact one of the mother class. As a matter of fact,
basically, is a pointless override:
/// surce file ( debug version )
namespace inet{
namespace tcp{
TCPSegment *
TCPConnection2
::
createTCPSegment
(const char * name)
{
/// This is the original line of code of the
TCPConnection::
createTCPSegment
(
const char * name
) function
return new TCPSegment(name);
};
} /// end of tcp namespace
} /// end of inet namespace
Now, here i'll explain
why i call this bug weird:
If i use the
code as it is now, the simulation will crash. If i erease completely my override, so that my
TCPConnection2
does call implicitly the mother class function
createTCPSegment
, then the code will work.
Isn't this weird?
The same line of code works if called by the mother class, but fails if called by the child class.
Anyway, my problem is just figure out how can i extend and use a TCPSegment2 class.
Does anybody have an intuition, or an idea?
Thanks in advice.
PS:
Any idea on the reason of the bug i explained?