0
votes

I am trying to set a parameter in PassiveQueueBase which is child class and call it in another child class PriorityScheduler for Base Class IPassiveQueue.

PriorityScheduler is inherited from SchedulerBase which has a pointer (inputQueue) pointing at who ever is of type IpassiveQueue and going to invoke PacketEnqueued() function to PriorityScheduler. This is shown in this code

class INET_API SchedulerBase : public cSimpleModule, public IPassiveQueue, public IPassiveQueueListener
{
    public:
    virtual void packetEnqueued(IPassiveQueue *inputQueue) override;
};

Note: IpassiveQueue.h has no .cc file it is an interface file for many other classes.

What I tried to do is shown below,

class INET_API IPassiveQueue
{
  public:
    simtime_t sendWindowStart;
    simtime_t sendWindowEnd;
    virtual void setWindows() {};
};

class INET_API PassiveQueueBase : public cSimpleModule, public IPassiveQueue
{  protected:
    void setWindows(simtime_t SWS,simtime_t SWE);
};

void PassiveQueueBase :: setWindows(simtime_t SWS,simtime_t SWE)
{   SWS = 3;  SWE = 4;                  
sendWindowStart = SWS;               
sendWindowEnd = SWE;             
};

bool PriorityScheduler::schedulePacket()
{
IPassiveQueue *pqueue;
pqueue->setWindows();
sendWindowStart = inputQueue->sendWindowStart;
sendWindowEnd = inputQueue->sendWindowEnd;
}

I had an error by running the simulation as shown below

Simulation terminated with exit code: 139 Working directory: /home/usrname/omnetpp-5.0/samples/inet/examples/mysimulation Command line: opp_run -r 0 -n ..:../../src:../../tutorials -l ../../src/INET --debug-on-errors=false omnetpp.ini

Also I have exclamation mark on this line

pqueue->setWindows();

with this note

‘Pqueue’ may be used uninitialized in this function [-Wmaybe-uninitialized]

2
Are you intend to use your modified queue's class as typical OMNeT++ queue? If yes, you should prepare a new class which inherits from PassiveQueueBase and IQueueAccess, where PassiveQueueBase is the class already existed in INET (not your class).Jerzy D.
well It was one step what I am showing in this question, because I want this variable to show up in DropTailQueue which again inherited from QueuePassiveBase. I am using DropTailQueue in the internal Queue of the switch. So I won't say it is my personal class still I am using omnet++ Queue.Mour_Ka
In your question you have presented IPassiveQueue class which is different that IPassiveQueue from INET. If you want to use an own queue I strongly suggest preparing a new class which inherits from PassiveQueueBase, and IQueueAccess. In this new class you may add own variables as well as own behaviour.Jerzy D.
sorry for the confusion, I got your point now. Will work on that.Mour_Ka

2 Answers

1
votes

you have not allocated pqueue yet and you are using it.

IPassiveQueue *pqueue;

this one still points on unknown location on memory.

to fix this you can allocate it using new

IPassiveQueue *pqueue = new IPassiveQueue;

and make sure to delete it using delete

delete pqueue;

you could also allocate it using smart pointer which will be more safe

std::unique_ptr<IPassiveQueue> pqueue(new IPassiveQueue);
0
votes

Well I thought about using inputQueue itsself as pointer instead of creating new pointer on the function that exactly the same as in the child class but empty and it worked.

class INET_API PriorityScheduler : public SchedulerBase
{
  protected:
    virtual bool schedulePacket() override;
    simtime_t sendWindowStart;
    simtime_t sendWindowEnd;
    simtime_t SWS;
    simtime_t SWE;
};

bool PriorityScheduler::schedulePacket()
{
    inputQueue->setWindows( SWS, SWE);
    sendWindowStart = inputQueue->sendWindowStart;
    sendWindowEnd = inputQueue->sendWindowEnd;
}

class INET_API IPassiveQueue
{
  public:
    simtime_t sendWindowStart;
    simtime_t sendWindowEnd;
    virtual void setWindows(simtime_t SWS,simtime_t SWE) {};
}

class INET_API PassiveQueueBase : public cSimpleModule, public IPassiveQueue
{
  protected:
    virtual void setWindows(simtime_t SWS,simtime_t SWE) {};
}

void PassiveQueueBase::setWindows(simtime_t SWS,simtime_t SWE)
{   SWS = 1; SWE=5;
sendWindowStart = SWS;
sendWindowEnd = SWE;
}