1

I want to use sockets inside my network simulation done with Omnet++, i am getting a collision of method name between:

  • send() method of Socket.
  • send() method defined by Omnet++, that allow exchange of msg between simulation modules.

The compiler recognize only send() method defined by Omnet++.

How can i resolve it ?

Thank you,

EDIT

In order to make it more clear, i will past a copy of my code:

GeoTraCIMobility.cc (CPP Code)

#include <limits>
#include <iostream>
#include <sstream>
//#include <cstring>      // Needed for memset
//#include <sys/socket.h> // Needed for the socket functions
//#include <netdb.h>      // Needed for the socket functions
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>

#include "mobility/geoTraCI/GeoTraCIMobility.h"

Define_Module(GeoTraCIMobility);

namespace {
    const double MY_INFINITY = (std::numeric_limits<double>::has_infinity ? std::numeric_limits<double>::infinity() : std::numeric_limits<double>::max());

    double roadIdAsDouble(std::string road_id) {
        std::istringstream iss(road_id);
        double d;
        if (!(iss >> d)) return MY_INFINITY;
        return d;
    }
}

void GeoTraCIMobility::Statistics::initialize()
{
    firstRoadNumber = MY_INFINITY;
    startTime = simTime();
    totalTime = 0;
    stopTime = 0;
    minSpeed = MY_INFINITY;
    maxSpeed = -MY_INFINITY;
    totalDistance = 0;
    totalCO2Emission = 0;
}

//OTHERS FUNCTIONS

// Function that create a socket and send data
void GeoTraCIMobility::requestingFromPyServer()
{
    std::string HOST = "127.0.0.1";
    int PORT = 19999;
    int MAX_BUFFER = 1024;

      int connectionFd, rc, index = 0, limit = MAX_BUFFER;
      struct sockaddr_in servAddr, localAddr;
      char buffer[MAX_BUFFER+1];


      memset(&servAddr, 0, sizeof(servAddr));
      servAddr.sin_family = AF_INET;
      servAddr.sin_port = htons(PORT);
      servAddr.sin_addr.s_addr = inet_addr(HOST.c_str());

      // Create socket
      connectionFd = socket(AF_INET, SOCK_STREAM, 0);

      /* bind any port number */
      localAddr.sin_family = AF_INET;
      localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
      localAddr.sin_port = htons(0);

      rc = bind(connectionFd,
          (struct sockaddr *) &localAddr, sizeof(localAddr));

      // Connect to Server
      connect(connectionFd,
          (struct sockaddr *)&servAddr, sizeof(servAddr));

      // Send request to Server
      std::string req= "ShortestPath_297162704_82660198";
      sprintf( buffer, "%s", req.c_str() );

      // UNRECOGNIZED SEND METHOD 
      send(connectionFd, buffer, strlen(buffer), 0 );
      // UNRECOGNIZED SEND METHOD

      close(connectionFd);

      printf("Client closed.\n");
}

GeoTraCIMobility.cc inherits from cSimpleModule the following send methods:

cSimpleModule.h

/**
 * Sends a message through the gate given with its ID.
 */
int send(cMessage *msg, int gateid)  {return sendDelayed(msg, SIMTIME_ZERO, gateid);}

/**
 * Sends a message through the gate given with its name and index
 * (if multiple gate).
 */
int send(cMessage *msg, const char *gatename, int gateindex=-1)  {return sendDelayed(msg, SIMTIME_ZERO, gatename, gateindex);}

/**
 * Sends a message through the gate given with its pointer.
 */
int send(cMessage *msg, cGate *outputgate)  {return sendDelayed(msg, SIMTIME_ZERO, outputgate);}
HanniBaL90
  • 535
  • 6
  • 18
  • 2
    Since Omnet++ is a C++ framework, doesn't it use classes or namespaces? Don't pull in symbols in the global namespace with the `using` keyword unless you know there are no collisions. Only pull in symbols you know to be safe, or use namespace aliasing if you think the namespace name is to long. – Some programmer dude May 25 '16 at 10:19
  • I didn't understand what you said here !? I looked for a manner to call the send() method of Sockets, by enclosing it with a namespace, after that i remember that there is no namespace with C. Also, i can't enclose my code in a manner to avoid the use of this method (send() method of Omnet++), since it is an herited method – HanniBaL90 May 25 '16 at 10:26
  • Omnet++ is a C++ framework, so it can't be used in a C program. Also, Omnet++ uses an `omnetcpp` namespace (if I read the documentation correctly), so if there is an `omnetcpp::send` function you should use that. ***Don't*** do `using namespace omnetcpp;` as that will pull in all symbols from the `omnetcpp` namespace into the global namespace, and you will have a collision with e.g. `send`. – Some programmer dude May 25 '16 at 10:28
  • Also, if the Omnet++ `send` function is an *inherited* function, then that means it is a *member function* inside a class, and not a standalone global function. Then there is no collision, as you need an instance of the class to be able to call the Omnet++ `send` function. Maybe you [need to relearn basic C++](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – Some programmer dude May 25 '16 at 10:30

1 Answers1

3

Use ::send(...) to access the global function in an OMNeT++ model. Otherwise the send() method inhertited from the cSimpleModule will be called.

Rudi
  • 6,418
  • 1
  • 16
  • 20