Creating Custom OF Controller

30 views
Skip to first unread message

Yoppy Yunhasnawa

unread,
Aug 15, 2016, 4:33:49 PM8/15/16
to ns-3-users
Hi,

I am new to NS3. I want to implement a custom controller by inheriting NS3 provided ns3::ofi::Controller.
I tried to make a new class called MyController in a directory inside scratch directory ("scratch/testdir/mycontroller.h" & "scratch/testdir/mycontroller.cc"), then I put some lines of code like this:

#ifndef MYCONTROLLER_H
#define MYCONTROLLER_H

#include "ns3/core-module.h"
#include "ns3/openflow-module.h"

class MyController : public ns3::ofi::Controller
{
public:
  MyController();
  void testMethod();
  static TypeId GetTypeId (void);
  void ReceiveFromSwitch (Ptr<OpenFlowSwitchNetDevice> swtch, ofpbuf* buffer);
};

#endif // MYCONTROLLER_H

When I tried to run using QtCreator, it gives me error: "TypeId has not been declared" and "Ptr has not been detected".
I'm not sure, but it seems that they are basic error messages related with data types. Yet, I don't have any idea about how to correct them. 

I have tried to copy, paste, rename and run the openflow-switch.cc example in the same directory and it doesn't give any error messages about Ptr, though there are many times Ptr is used there. I guess it is because openflow-switch.cc is not a class, but I have read in this group that it is okay to put class in scratch subdirectory as long as we have only 1 main file. So in my case, why Ptr has not been declared? I really don't understand.. :(

Could anybody please explain me how to inherit ns3::ofi::Controller correctly? 

Tommaso Pecorella

unread,
Aug 15, 2016, 6:35:41 PM8/15/16
to ns-3-users
Hi,

you're missing the namespace inclusions.
Check any ns-3 header and search for something like:
namespace ns3 {


Cheers,

T.

Yoppy Yunhasnawa

unread,
Aug 16, 2016, 5:25:59 PM8/16/16
to ns-3-users
It works now! Thank you very much for your help Sir.
Reply all
Reply to author
Forward
0 new messages