Error when trying to receive and treate different kind of packet in a server

179 views
Skip to first unread message

Adriana V R

unread,
Apr 25, 2016, 10:49:01 AM4/25/16
to OMNeT++ Users
Hello, I am trying to create a UDP server-client Application based on UDPVideoStreamSvr and UDPVideoStreamCli. However, I want to traffic a packet that I created:

packet CCNPacket {
    string name;
    int part;
    bool isInterest;
    string content;
}

So, I can create a CCNPacket in the client class and send it to server:

void UDPMasterCli::requestStream()
{
    int svrPort = par("serverPort");
    int localPort = par("localPort");
    const char *address = par("serverAddress");
    L3Address svrAddr = L3AddressResolver().resolve(address);

    if (svrAddr.isUnspecified()) {
        EV_ERROR << "Server address is unspecified, skip sending video stream request\n";
        return;
    }

    EV_INFO << "Requesting video stream from " << svrAddr << ":" << svrPort << "\n";

    socket.setOutputGate(gate("udpOut"));
    socket.bind(localPort);

    int isInterest = rand() % 1;

    std::ostringstream str;
    str << rand() % 100;
    name = "CCNPacketServer-" + str.str();
    CCNPacket *CCNPk = new CCNPacket();
    CCNPk->setName(name.c_str());
    CCNPk->setPart(1);

    if (isInterest == 1)
        CCNPk->setIsInterest(true);
    else
        CCNPk->setIsInterest(false);
    
    CCNPk->setContent("CCN Packet");
    EV_INFO << "CCN Packet. Name " << CCNPk->getName() <<"Part" << CCNPk->getPart() << "Is interest?" << CCNPk->getIsInterest() << endl;

    CCNPk->setByteLength(1);
    socket.sendTo(CCNPk, svrAddr, svrPort);
}

My problem is: how to receive and treat this packet on the server in the processStreamRequest function:

void UDPMasterSvr::processStreamRequest(CMessage *msg)
{
   if (pk->getIsInterest()) {
        EV_INFO << "It's an interest packet" << pk->getName() << "\n";
    }
    else {
        EV_INFO << "It's a data packet " << pk->getName() << "\n";
    }
}

The following error message shows up if I try to use the function above: msg and CMessage was not declared in this scope; and variable or field declared void.

If I try to use: void UDPMasterSvr::processStreamRequest(CCNPacket *pk) an error message shows up in INETDefs.h in the defition of the check_and_cast function

If I try to use UDPMasterSvr::processStreamRequest(CPacket *pk) I can't access the parameters of my CCNPacket, just the CPacket parameters.


So, what am I doing wrong? Can anyone help me?




Alfonso Ariza Quintana

unread,
Apr 25, 2016, 11:36:39 AM4/25/16
to omn...@googlegroups.com

void UDPMasterSvr::processStreamRequest(CMessage *msg)

{

   if (pk->getIsInterest()) {

        EV_INFO << "It's an interest packet" << pk->getName() << "\n";

    }

    else {

        EV_INFO << "It's a data packet " << pk->getName() << "\n";

    }

}

 

It is cMessage, not CMessage

 

 

pk is undefined, and it is possible to receive a packet that it isn’t of type CNNPacket

 

you should do

 

CNNPacket *pk = dynamic_cast<CNNPacket *> (msg);

 

if (pk) {

     …..

}

 

 

Also, you have an error here

 

  socket.setOutputGate(gate("udpOut"));

    socket.bind(localPort);

 

 

This lines should be in requestStream() you only need to bind the port one time or if you change the port, if the port number doesn’t change, the bind of the port and the select of the output gate should be in the initialize method.

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
Visit this group at https://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

Adriana V R

unread,
Apr 26, 2016, 8:25:58 AM4/26/16
to OMNeT++ Users, aari...@hotmail.com
Thank you! It's working now!
Is there any difference between "dynamic_cast" and "check_and_cast"? Both work here. And in the manual I just saw this: 

The check_and_cast<>() template function on the second line is part of OMNeT++. It performs a standard C++ dynamic_cast, and checks the result: if it is NULL, check_and_cast raises an OMNeT++ error. Using check_and_cast saves you from writing error checking code: if calleeModule from the first line is NULL because the submodule named "callee" was not found, or if that module is actually not of type Callee, an error is thrown from check_and_cast.


  socket.setOutputGate(gate("udpOut"));

    socket.bind(localPort);


These lines are already in requestStream(),  I didn't change that.

And thanks again.

Alfonso Ariza Quintana

unread,
Apr 27, 2016, 10:13:05 AM4/27/16
to omn...@googlegroups.com

Check_and_cast does a dynamic_cast and if the result is null it throws an exception

Adriana V R

unread,
May 3, 2016, 11:52:33 AM5/3/16
to OMNeT++ Users, aari...@hotmail.com
One more question:

I have a client and a server. When an interest packet arrives in the server, it verifies if there is a data packet for this interest. If exist, it send the data packet back to the client:


CCNPacket *data = new CCNPacket();
data
->setName(cache[i].getName().c_str());
data
->setPart(cache[i].getPart());
data
->setContent(cache[i].getContent().c_str());
socket
.sendTo(data, CCNPk->getSrcAddress(), clientPort);

I create the data packet and I know the source address because when a client sends an interest packet I set it:

L3Address srcAddr = L3AddressResolver().resolve(getParentModule()->getFullName());

std
::ostringstream str;
str
<< rand() % 10;
name
= "CCNPacket-" + str.str();

CCNPacket *CCNPk = new CCNPacket();
CCNPk->setName(name.c_str());
CCNPk->setPart(1);
CCNPk->setSrcAddress(srcAddr);

The question is: how can I figure out which is the clientPort?

Ekar

unread,
May 4, 2016, 1:34:59 AM5/4/16
to OMNeT++ Users
Hi Adriana;
              I am also using the Application based on UDPVideoStreamSvr and UDPVideoStreamCli. I have problem when I run this application.
<!> Error in module (VoDUDPServer) scenario.server.udpApp[0] (id=38) during network initialization: std::bad_alloc: std::bad_alloc.

I have downloaded the template file from this site=> 
http://www-tkn.ee.tu-berlin.de/research/trace/ltvt.html
and my omnetpp.ini file is like this:

# application config
**.vod_trace_file="Terse_Simpsons16.dat"
**.traceType="SVC"
**.startTime = 0.5s
*.server.udpApp[*].clientsStartStreamTime = 10

**.node[*].udpApp[*].typename = "VoDUDPClient"
**.node[*].udpApp[*].localPort = 3000

**.server.udpApp[*].typename = "VoDUDPServer"
**.server.udpApp[*].localPort = 3088+ancestorIndex(0)
**.server.udpApp[*].destPort = 3000
*.server.udpApp[*].destAddresses = "node[0] node[1] node[2] node[3] node[4] node[5]"

Can you please share any idea if you have on this issue?

Thank you.

Adriana V R

unread,
May 4, 2016, 7:00:38 PM5/4/16
to OMNeT++ Users
Hi Ekar,

The std::bad_alloc is a c++ error. Did you look for it in the forum topics or google? I don't know how to fix but maybe there are some ideas here or in the Google. When I used the UDPVideoStreamSvr and UDPVideoStreamCli without modifications performs perfectly. The only differente is that I didn't use this lines in omnetpp.ini:


**.vod_trace_file="Terse_Simpsons16.dat"
**.traceType="SVC"

Adriana V R

unread,
May 4, 2016, 7:02:20 PM5/4/16
to OMNeT++ Users, aari...@hotmail.com
Resolution:

UDPDataIndication *ctrl = check_and_cast<UDPDataIndication *>(CCNPk->removeControlInfo());
L3Address srcAddress
= ctrl->getSrcAddr();
int srcPort = ctrl->getSrcPort();
delete ctrl;

// send back

socket
.sendTo(data, srcAddress, srcPort);

Alfonso Ariza Quintana

unread,
May 5, 2016, 9:10:06 AM5/5/16
to omn...@googlegroups.com

If you are using UDP the sender port is in the controlInfo, if you are working in the network layer, you need to “open” the received packet.

Reply all
Reply to author
Forward
0 new messages