28 #include <netinet/in.h> 29 #include <sys/types.h> 30 #include <sys/socket.h> 61 NetBridge::NetBridge(std::string name) :
TimedModel(name) {
64 std::ofstream::out | std::ofstream::trunc);
66 std::ofstream::out | std::ofstream::trunc);
71 this->
GetName() +
".signalUdpIntr");
74 #ifdef NETBRIDGE_ENABLE_LOG_INPUT 78 #ifdef NETBRIDGE_ENABLE_LOG_OUTPUT 95 <<
"Virtual Ethernet Adapter is up." << std::endl
109 std::cout <<
"unable to create new thread using lpthread." 211 #ifdef NETBRIDGE_ENABLE_LOG_INPUT 214 int32_t z = x + y * 4;
216 std::chrono::time_point<std::chrono::system_clock> now;
217 now = std::chrono::system_clock::now();
219 auto duration = now.time_since_epoch();
221 std::chrono::duration_cast<std::chrono::milliseconds>(
227 <<
" TO #" << z << std::endl << std::flush;
284 #ifdef NETBRIDGE_ENABLE_LOG_OUTPUT 287 std::chrono::time_point<std::chrono::system_clock> now =
288 std::chrono::system_clock::now();
289 auto duration = now.time_since_epoch();
291 std::chrono::duration_cast<std::chrono::milliseconds>(
294 output_debug <<
"[" << millis <<
"] OUT " << _trafficOut
297 <<
" FROM #" << x << std::endl << std::flush;
383 char decimal_port[16];
384 snprintf(decimal_port,
sizeof(decimal_port),
"%d",
f_port);
385 decimal_port[
sizeof(decimal_port) /
sizeof(decimal_port[0]) - 1] =
'\0';
386 struct addrinfo hints;
387 memset(&hints, 0,
sizeof(hints));
388 hints.ai_family = AF_UNSPEC;
389 hints.ai_socktype = SOCK_DGRAM;
390 hints.ai_protocol = IPPROTO_UDP;
391 int r(getaddrinfo(addr.c_str(), decimal_port, &hints, &
f_addrinfo));
394 + addr +
":" + decimal_port +
"\"").c_str());
398 SOCK_CLOEXEC, IPPROTO_UDP);
403 + addr +
":" + decimal_port +
"\"").c_str());
511 char decimal_port[16];
512 snprintf(decimal_port,
sizeof(decimal_port),
"%d",
f_port);
513 decimal_port[
sizeof(decimal_port) /
sizeof(decimal_port[0]) - 1] =
'\0';
514 struct addrinfo hints;
515 memset(&hints, 0,
sizeof(hints));
516 hints.ai_family = AF_UNSPEC;
517 hints.ai_socktype = SOCK_DGRAM;
518 hints.ai_protocol = IPPROTO_UDP;
519 int r(getaddrinfo(addr.c_str(), decimal_port, &hints, &
f_addrinfo));
523 (
"invalid address or port for UDP socket: \"" + addr +
":" 524 + decimal_port +
"\"").c_str());
528 SOCK_CLOEXEC, IPPROTO_UDP);
533 (
"could not create UDP socket for: \"" + addr +
":" + decimal_port
541 (
"could not bind UDP socket with: \"" + addr +
":" + decimal_port
608 return ::recv(
f_socket, msg, max_size, 0);
634 struct timeval timeout;
635 timeout.tv_sec = max_wait_ms / 1000;
636 timeout.tv_usec = (max_wait_ms % 1000) * 1000;
645 int retval = select(
f_socket + 1, &s, 0, 0, &timeout);
653 return ::recv(
f_socket, msg, max_size, 0);
The Signal class models a generic bus of width equals to the sizeof(T)
uint8_t _recv_buffer[RECV_BUFFER_LEN]
udp_server(const std::string &addr, int port)
Initialize a UDP server object.
#define NETSOCKET_SERVER_PORT
uint8_t _send_buffer[SEND_BUFFER_LEN]
void push(T)
Pushes an object to the back of the buffer.
int get_port() const
The port used by this UDP server.
udp_client(const std::string &addr, int port)
Initialize a UDP client object.
This class models a TimedModel.
std::string get_addr() const
Return the address of this UDP server.
void SetOutputBuffer(Buffer< FlitType > *)
#define NETSOCKET_SERVER_ADDRESS
std::ofstream output_debug
T top()
Peeks at the top of the buffer.
SimulationTime Run()
Runs a state.
void Reset()
Return the module to its initial state (if stateful).
uint32_t full()
Returns TRUE when the buffer is full.
NetBridgeSendState _send_state
Signal< int8_t > * _signal_recv
uint32_t _flits_to_send_count
T Read()
Get the last value writen to the bus.
int get_socket() const
The socket used by this UDP server.
Buffer< FlitType > * GetInputBuffer()
~udp_client()
Clean up the UDP client object.
void Write(T val)
Writes some value to the bus.
int get_port() const
Retrieve the port used by this UDP client.
std::string GetName()
Getter method for the <_name> field.
int timed_recv(char *msg, size_t max_size, int max_wait_ms)
Wait for data to come in.
std::string get_addr() const
Retrieve a copy of the address.
Signal< int8_t > * GetSignalRecv()
volatile int udpRecvThread_terminate
NetBridgeRecvState _recv_state
~udp_server()
Clean up the UDP server.
int send(const char *msg, size_t size)
Send a message through this UDP client.
struct addrinfo * f_addrinfo
static void * udpRecvThread(void *)
struct addrinfo * f_addrinfo
int get_socket() const
Retrieve a copy of the socket identifier.
std::ofstream output_uart
udp_server * GetUdpServer()
#define NETSOCKET_CLIENT_ADDRESS
void LogWrite(std::string)
uint32_t size()
Counts elements from the buffer.
void pop()
Removes the object at the front of the buffer.
int recv(char *msg, size_t max_size)
Wait on a message.
uint32_t _flits_to_recv_count
#define NETSOCKET_CLIENT_PORT