Main Page   Data Structures   File List   Data Fields   Globals  

driver.c File Reference

A simple NSDS driver for the neesgrid project. See http://www.mcs.anl.gov/neesgrid/ for more information, or the main Doxygen page. More...

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <pthread.h>
#include <getopt.h>
#include "nsds_util.h"
#include "flog.h"

Go to the source code of this file.

Data Structures

struct  data_thread_arg
 Struct passed to data thread. More...


Functions

void sighandler (int signal)
 Control-break handler. Sets global flag to indicate exit request.

int tcp_send_driverids (const uint16_t control_socket, const uint16_t data_socket, const char *daq_name)
 Send 'driver IDs' on control and data sockets to NSDS.

void * data_thread_main (void *arg)
 Thread for data forwarding.

int data_thread_startup (data_thread_arg d_arg)
 Data channel thread clean- and start-up.

int cmd_handler (const uint16_t nsds_s_ctrl, const uint16_t nsds_s_data, const uint16_t daq_control, const uint16_t daq_data, const char *daq_name)
 Read commands on control channel and respond.

void main_loop (const char *daq_machine, const uint16_t daq_port, const char *nsds_machine, const uint16_t nsds_port, const char *driver_name)
 Connect up the net, do the plumbing, call the worker.

int main (int argc, char *argv[])
 Parse command line, setup + run main loop.


Variables

const int SRV_PORT = 42420
 TCP server port on NSDS that we should connect to. Cmd-line override-able.

const int QUEUE_LENGTH = 1
 TCP connection queue length.

const int NUM_THREADS = 2
 Number of threads - main and data.

const size_t DATA_READ_SIZE = 256
 Number of bytes to read at a time on the data thread.

const time_t RATE_UPDATE_PERIOD = 10
 Screen update rate, in seconds, for data rate printout.

bool control_break
 Global boolean set by signal handler to force exit.

bool streaming_active
 Global boolean, tells data thread to exit.


Detailed Description

A simple NSDS driver for the neesgrid project. See http://www.mcs.anl.gov/neesgrid/ for more information, or the main Doxygen page.

Author:
Paul Hubbard
Date:
8/27/02
Note:
We require the flog message library as of 9/24/02.

Definition in file driver.c.


Function Documentation

int cmd_handler const uint16_t    nsds_s_ctrl,
const uint16_t    nsds_s_data,
const uint16_t    daq_control,
const uint16_t    daq_data,
const char *    daq_name
 

Read commands on control channel and respond.

Currently handles welcome. All others forwarded verbatim to the DAQ.

The only complexity is polling the command channel, and then checking the status of the data stream now and then. This is a patch around broken idiocy in the NSDS, which operates on the don't-ask-don't-tell blinders mode.

Note:
Not the cleanest code ever written; this has evolved several times now.
Very much a work in progress
Date:
8/27/02

Definition at line 367 of file driver.c.

References MAX_CMD_LEN, streaming_active, tcp_nl_read(), tcp_nl_write(), and tcp_send_driverids().

Referenced by main_loop().

void* data_thread_main void *    arg
 

Thread for data forwarding.

Read the data, parse it, forward channels that are in use.

Note:
Fixed size command buffers - must be fixed. Pardon the pun.
Date:
9/16/02
Return values:
NULL  always
Parameters:
arg  Ptr to struct with FDs for send and rcv sockets
Note:
Bails out on any error whatsoever!

Definition at line 217 of file driver.c.

References control_break, data_thread_arg::daq_data, DATA_READ_SIZE, MAX_CMD_LEN, data_thread_arg::nsds_data, RATE_UPDATE_PERIOD, and streaming_active.

Referenced by data_thread_startup().

int data_thread_startup data_thread_arg    d_arg
 

Data channel thread clean- and start-up.

Starts thread w/data struct defining various file descriptors.

Note:
Thread runs detached.
Return values:
0  if OK, non-zero otherwise
Parameters:
d_arg  Struct w/port FDs in it
Date:
9/24/02

Definition at line 320 of file driver.c.

References data_thread_main(), NUM_THREADS, pthread_setconcurrency(), and streaming_active.

Referenced by main_loop().

int main int    argc,
char *    argv[]
 

Parse command line, setup + run main loop.

Set up logging, install signal handler, parse command line, run the work routine.

Note:
Uses getopt for options
Parameters:
argc  Argc as passed by shell
argv  Argv as passed by shell
Returns:
0 All is good Non-zero All is not good

Definition at line 661 of file driver.c.

References control_break, main_loop(), and sighandler().

void main_loop const char *    daq_machine,
const uint16_t    daq_port,
const char *    nsds_machine,
const uint16_t    nsds_port,
const char *    driver_name
 

Connect up the net, do the plumbing, call the worker.

This calls connect four times - control & data for both DAQ and NSDS. We do the DAQ first, since there's no point talking to the NSDS unless we can reach the DAQ system.

Quite a bit of smarts - connections are retried, knows how to restart, fairly robust against network failure.

Note:
Any communications error causes a complete set of reconnects. Cautious, yes.
Parameters:
daq_machine  Name or ip address of DAQ
daq_port  TCP port on DAQ
nsds_machine  Name or IP address of NSDS
nsds_port  TCP port on NSDS
driver_name  String to use in driver ID, as per LP
Note:
Wait times defined here, could make global for readability
Date:
8/28/02

Definition at line 502 of file driver.c.

References cmd_handler(), control_break, data_thread_arg::daq_data, data_thread_startup(), data_thread_arg::nsds_data, streaming_active, tcp_close(), tcp_connect_retry(), and tcp_peername().

Referenced by main().

void sighandler int    signal
 

Control-break handler. Sets global flag to indicate exit request.

Assumes Installed in interrupt chain by someone else

Parameters:
signal  Signal number
Date:
3/25/02

Definition at line 138 of file driver.c.

References control_break.

Referenced by main().

int tcp_send_driverids const uint16_t    control_socket,
const uint16_t    data_socket,
const char *    daq_name
 

Send 'driver IDs' on control and data sockets to NSDS.

Sends out driver IDs on control and data channels to NSDS. The base name can be set my the corresponding command line option, so that you can run more than one per host.

Note that the DAQ never sees the 'welcome' command - its entirely handled by the driver. It is, after all, a driver ID.

Note:
For now, hardwired until better understood by YT
Parameters:
control_socket  Control channel socket
data_socket  Data channel socket
daq_name  String to unique-ify driver IDS
Return values:
0  if no problems

Definition at line 175 of file driver.c.

References tcp_nl_write().

Referenced by cmd_handler().


Variable Documentation

bool control_break
 

Global boolean set by signal handler to force exit.

Definition at line 113 of file driver.c.

Referenced by data_thread_main(), main(), main_loop(), and sighandler().

const size_t DATA_READ_SIZE = 256
 

Number of bytes to read at a time on the data thread.

Definition at line 107 of file driver.c.

Referenced by data_thread_main().

const int NUM_THREADS = 2
 

Number of threads - main and data.

Definition at line 104 of file driver.c.

Referenced by data_thread_startup().

const int QUEUE_LENGTH = 1
 

TCP connection queue length.

Definition at line 101 of file driver.c.

Referenced by tcp_socket_make().

const time_t RATE_UPDATE_PERIOD = 10
 

Screen update rate, in seconds, for data rate printout.

Definition at line 110 of file driver.c.

Referenced by data_thread_main().

const int SRV_PORT = 42420
 

TCP server port on NSDS that we should connect to. Cmd-line override-able.

Definition at line 98 of file driver.c.

Referenced by tcp_socket_make().

bool streaming_active
 

Global boolean, tells data thread to exit.

Definition at line 116 of file driver.c.

Referenced by cmd_handler(), data_thread_main(), data_thread_startup(), and main_loop().


Generated on Fri Dec 6 14:33:16 2002 for NSDS Driver by doxygen1.2.18