|
The ASIST/Ethernet software component is a set of application development tools that assists VCO/4K customers in developing host-controlled applications. This tool kit offers programmers a means to provide data communications services to a call processing application.
The ASIST/Ethernet component is application-layer software that allows a UNIX-based host to communicate with a VCO/4K. This product implements the Ethernet protocol, and allows the programmer to concentrate on the application rather than on low-level, host-to-switch communication issues. ASIST/Ethernet is ideal for the application developer who needs to prototype applications quickly in a laboratory environment.
ASIST/Ethernet is written specifically for the Sun Microsystems SunOS operating system.
The ASIST/Ethernet component was designed with the following requirements:
ASIST/Ethernet is written in the C programming language.
The Ethernet Link Manager and the Ethernet Communication Driver communicate information to each other via a standard message format. This message format consists of Commands, Acknowledgments, Ethernet Packet Data, Error Reports and Link Statistics.
The application can send the following commands to the driver:
These message types are sent by the Ethernet Driver to the application process in response to a successfully executed command.
Data packets contain Ethernet message data. Data packets are sent in both directionsApplication to Ethernet Communications Driver and Ethernet Communications Driver to Application.
Error packets are sent by the Ethernet Communictions driver to the application to report faulty conditions on a link or the state of the read and write queues. Error packets are also sent if a command could not be executed successfully.
The Ethernet Driver responds to a Send Statistics command by sending a Statistics packet. This packet contains various counter values for a given link.
The following structure is the C language representation of the Link Manager-Communication Driver interface format. This data structure is located in the enet_if.h file.
typedef struct
}
ushort bytecount;
byte pkt_type;
union {
DATA_PKT qdata_pkt;
LINK_STATS qstat_pkt;
ERROR_PKT qerr_pkt;
ACK_PKT qack_pkt;
CMD_PKT qcmd_pkt;
PARAMS qpara_pkt;
q_data;
}
Q_PKT;
The following is a sample configuration file for the Ethernet Communications Driver:
/*Sample configuration file for VCO/4K system #1*/
log file: test.log
log level: 1
network a name: j_jetson
network a local: 2121
network a remote: 2122
network b name: g_jetson
betwork b local: 2021
network b remote: 2022
The definitions of the configuration file parameters are as follows:
log fileThe name of the log file you want to create (or append to) for each log message function call. The log file name is a standard UNIX file name and may be up to 256 characters in length. If a log file name is not specified, the system uses the default, which is ./enetdrvr.log.
log levelThe level of logging you want to output to the file. The level is from 0 to 4, where level 0 logs the least information and level 4 logs the most information.
network a nameThe Ethernet node name assigned to the ACTIVE side of the VCO/4K system to which you are communicating.
network a localThe local port number for the Ethernet host configuration on the ACTIVE side of the VCO/4K system. The value for this parameter is specified in the Local Port field on the VCO/4K Host Configuration screen.
network a remoteThe remote number associated with "network a local" for the ACTIVE side of the VCO/4K system. The value for this parameter is specified in the Rem Port field on the VCO/4K Host Configuration screen.
network b nameThe Ethernet node name assigned to the standby side of the VCO/4K system to which you are communicating.
network b localThe local port number for the Ethernet host configuration on the STANDBY side of the VCO/4K system. The value for this parameter is specified in the Local Port field on the VCO/4K Host Configuration screen.
network b remoteThe remote number associated with "network b local" for the ACTIVE side of the VCO/4K system. The value for this parameter is specified in the Rem Port field on the VCO/4K Host Configuration screen.
The ASIST products were developed on a Sun Microsystems SPARCstation. While the ASIST product is independent of any particular operating system, the ASIST/Ethernet product requires a UNIX operating system environment.
This section contains a list of the media contents of the ASIST/Ethernet disk and a description of the installation and compilation procedure.
All ASIST/Ethernet files reside on a 3.5-inch diskette (1.44 Mb). The directory of this diskette is as follows:
/asist/enet/control.c
datapath.c
enet.h
enetdrvr.c
enetdrvr.make
enet_if.h
enet_mgr.c
enet_mgr.make
enet_util.c
host.c
network.c
types.h
To copy the ASIST files from the supplied media, enter the appropriate UNIX tar command as shown below.
For systems running SunOS:
For systems running System V:
Each ASIST product includes a makefile for all the source modules. To compile the ASIST/Ethernet product, use the enet_mgr.make file.
The C language flag -DBSD is used in each makefile. When present, this flag indicates that the target operating system is SunOS; its absence indicates a System V environment.
The ASIST/Ethernet product contains the following functional areas:
Note The ENET Utilities module uses the same data structures and constants as the ENET Link Manager. |
The C language source files and functions provided by each of the functional areas are as follows.
Files: | enet_if.h/enet_mgr.c |
Functions: | Prepare Data Packet |
Files: | enet.h/control.c/datapath.c/enetdrvr.c/host.c/network.c |
Functions: | Create FIFO Name |
File: | enet_if.h/enet_util.c |
Functions: | Open And Write To File |
| File Name: |
| enet_if.h |
*/ |
|
|
|
#define MAX_CFG_NAME | 30 | /* Max characters in config file name */ | |
/*
|
|
|
|
Data packets contain single link message. Data packets are sent by the applicaton to the driver,to be transmitted . Similarly driver after deblocking the received link packet, sends it to the application.
*/
|
|
|
|
|
|
typedef struct
|
|
|
|
| |
|
| {
|
|
|
|
|
|
| long | unused; |
|
|
|
| unsigned short bytecount; | /* no of data characters */ | |
|
|
| unchar data[MAX_MSG_LENGTH];
| ||
|
| }
|
|
|
|
DATA_PKT;
|
|
|
|
| |
#define DATAPKTSIZE
|
| sizeof (DATA_PKT)
| |||
typedef struct
|
|
|
|
| |
|
| { |
|
| |
CMD_PKT;
| |||||
#define CMDPKTSIZE |
| sizeof (CMD_PKT) | |||
/* |
|
|
|
|
|
| command packets are sent only by the application to the driver. | ||||
*/
|
|
|
|
|
|
#define PORT_DEINIT
#define PORT_INIT
#define PORT_ACTIVE
#define PORT_DEACTIVE
#define SEND_STATS
#define SET_FIFO_DEBUG
#define SET_LINK_DEBUG
| 0
1
2
3
4
5
6
| /* turn off the initialized port */
/* initialize only, no polling */
/* start polling */
/* stop polling */
/* get statistics */
/* Set SHOW_DRVR_FIFO debug option */
/* Set SHOW_DATA_LINK debug option */
|
typedef struct
|
|
| |||
|
| {
|
|
|
|
|
|
| long | unused; | /* info pertains to this link */ |
|
| }
|
|
|
#define ACKPKTSIZE
|
|
| |||
sizeof (ACK_PKT)
|
| ||||
typedef
struct
|
|
|
|
| |
|
| {
|
|
|
|
|
|
| long | unused; |
|
|
| }
|
|
|
|
ERROR_PKT;
|
|
| |||
#define ERRPKTSIZE
| sizeof (ERROR_PKT)
|
| |||
/* |
#define INIT_FAIL
#define PORT_INACTIVE
#define POLLING_FAIL
#define RNR
#define TX_FAIL
#define NACKS_2MANY
#define MSG_2LONG
| 0
1
2
3
4
5
6
| /* Port initialization failed */
/* port is not in active state */
/* No response in max attempts */
/* Secondary not ready */
/* No ack till max xmt attempts */
/* primary sent max nacks in a row */
/* Number of characters > MAX_MSG_LENGTH */
|
typedef struct
|
|
| ||
| {
|
|
|
|
|
| ulong
ulong
ulong
ulong
ulong
ulong
ulong
ulong
ulong
ulong
ulong
| unused;
Npolled;
Nno_eots;
Ntxed_msgs;
Ntx_attempts;
Nnacks;
Ntx_blk_msgs[MAX_BLKS];
Nrxed_msgs;
Nlrc_errs;
Nrx_blk_msgs[MAX_BLKS];
Nno_response;
|
/* Total No of times tty polled */
/* Total no of times no EOTS */
/* No. of msgs txed successfully */
/* No. of transmissioins */
/* No of NACKS sent */
/* No. of multiblocked msgs txed */
/* No of msgs rxed */
/* No of LRC errors */
/* No. of multiblocked msgs rxed */
/* No of times secondary failed to
*/
|
| }
|
|
|
|
LINK_STATS;
|
|
| ||
#define STATPKTSIZE
| sizeof (LINK_STATS)
|
| ||
/*
structure containing the configurable parameter values. On getting this structure the
driver updates its own copy. For the changes concerning baud rate, parity and stopbits
to become effective, PORT_INIT command needs to be issued. | ||||
|
|
#define MAXPARACHARS8
| /* Maximum chars for any parameter name
*/
| |||
| typedef struct
|
| ||
| {
|
|
|
|
| long
| unused;
|
| |
| char
| cfg_name[MAX_CFG_
NAME];
| /* tty device name */
| |
| } |
|
|
|
PARAMS |
| |||
| {
|
|
|
|
| unsigned short bytecount;
|
| ||
| byte
| pkt_type;
| /*type of this queue packet */
| |
| union
|
|
| |
|
| {
|
|
|
|
| DATA_PKT qdata_pkt; |
| |
|
q_data;
}
|
| ||
Q_PKT;
|
|
|
/*
Type of packets to be exchanged between the driver and the application of the FIFO.
/*
| ||||
| #define DATA_TYPE
#define STATS_TYPE
#define EROR_TYPE
#define CMD_TYPE
#define ACK_TYPE
#define PARAM_TYPE
| 1
2
3
4
5
6
| ||
/*
| used as an index into the enet_mngr [] table */
| |||
| #define LOGICAL_LINK_0
#define LOGICAL_LINK_1
#define LOGICAL_LINK_2
#define LOGICAL_LINK_3
#define LOGICAL_LINK_4
#define LOGICAL_LINK_5
#defineLOGICAL_LINK_6
#define LOGICAL_LINK_7
| 0
1
2
3
4
5
6
7
| ||
| #define MAX_LINKS
#define MAX_FIFO_NAME
| 8
20
| /*Maximum possible communication links */
/* Maximum characters for FIFO name */ | |
/* Commands supported by the driver interface */ | ||||
| #defineCREATE_DRV
#define TERM_DRVR
#define LINK_INIT
#define LINK_DEINIT
#define LINK_ACTIVATE
#define LINK_DEACTIVATE
#define SEND_PARAMS
#define GET_STATS
#define SHOW_LINKS
|
| 1
2
3
4
5
6
8
9
10
|
typedef struct
|
|
| ||
| {
|
|
|
|
|
| int
char
char
int
int
char
byte
| drvr_pid;
destn_fifo [MAX_FIFO_NAME];
source_fifo [MAX_FIFO_NAME];
destn_fd;
source_fd;
cfg_name [MAX_CFG_NAME];
link_state;
|
|
| }
|
|
|
|
APP_ENET;
|
|
|
make_datapkt, get_qpkt, check_qstate, send_toq, create_comm,init_enet, stop_enet, init_linkmngr, process_cmd, send_drvr_cmd, create_drvr, show_process, enet_read, enet_write, makefifo, fifoname, terminate_drvr
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#if defined(BSD)
#include <sys/wait.h>
#endif
#include "types.h"
#include "enet_if.h"
DATA_PKT *make_datapkt();
int get_qpkt();
uchar check_qstate();
int send_toq();
int create_comm();
int init_enet();
int stop_enet();
void init_linkmngr();
void process_cmd();
void send_drvr_cmd();
void create_drvr();
void show_process();
int enet_read();
int enet_write();
int makefifo();
void terminate_drvr();
APP_ENET enet_mngr[MAX_LINKS];
Q_PKT ipdata, *ipptr;
DATA_PKT thisdata, *dataptr;
CMD_PKT thiscmd, *cmdptr;
ACK_PKT thisack, *ackptr;
ERROR_PKT thiserror, *errorptr;
LINK_STATS thisstatus, *statusptr;
DATA_PKT *make_datapkt(uchar *buf, ushort bytecount)
DATA_PKT thisdata
Parameter | Type | Use | Description |
---|---|---|---|
buf | uchar* | input | Data from application |
bytecount | ushort | input | Buffer size |
This function copies "bytecount" number of bytes from "buf" into the DATA_PKT "thisdata." It returns a pointer to "thisdata."
int get_qpkt(ushort type)
Q_PKT *ipptr;
DATA_PKT *dataptr;
CMD_PKT *cmdptr;
Parameter | Type | Use | Description |
---|---|---|---|
type | ushort | input | Q_PKT identifier |
This function prepares the Q_PKT structure, pointed to by "ipptr," to be sent to the ENET Driver process. Valid "type" identifiers for this function are as follows:
DATA_TYPE
CMD_TYPE
PARAM_TYPE
This function copies the appropriate information into the correct location of the Q_PKT. For PARAM_TYPE it calls the "make_parapkt()" function. If successful, it returns a value greater than zero; otherwise it returns FAILED.
uchar check_qstate(ushort linkid)
APP_ENET enet_mngr[];
uchar process_stat[];
Q_PKT *ipptr;
Parameter | Type | Use | Description |
---|---|---|---|
linkid | ushort | input | Link identifier |
This function checks if the ENET Driver process has sent any Q_PKT structures to the ENET Link Manager. The queue is identified in "enet_mngr[linkid].source_fd." It copies available data into the appropriate location in the Q_PKT structure, pointed to by "ipptr" and calls the "read()" system call. It returns the type of Q_PKT received; otherwise NULL.
int send_toq(ushort linkid)
APP_ENET enet_mngr[];
uchar process_stat[];
Q_PKT *ipptr;
Parameter | Type | Use | Description |
---|---|---|---|
linkid | ushort | input | Link identifier |
This function writes the Q_PKT structure to the ENET Driver process. The queue is identified in "enet_mngr[linkid].destn_fd". It calls the "write()" system call. This function returns one of the following values:
int create_comm(char path[], char name[], ushort linkid)
Parameter | Type | Use | Description |
---|---|---|---|
path | char | input | "./enetdrvr" for ENET (or file name and directory path) |
name | char | input | "enetdrvr" for ENET |
linkid | ushort | input | Link identifier |
This function spawns another ENET Communications Driver Process. It sets and opens the FIFO files and returns one of the following values:
int init_enet(ushort linkid, char *config, char *path, char *program)
Q_PKT ipdata *ipptr;
DATA_PKT thisdata *dataptr;
CMD_PKT thiscmd *cmdptr;
ACK_PKT thisack, *ackptr;
ERROR_PKT thiserror, *errorptr;
LINK_STATUS thisstatus, *statusptr;
Parameter | Type | Use | Description |
---|---|---|---|
linkid | ushort | input | Link ID |
*config | char pointer | input | ENET configuration file name |
*path | char pointer | input | ENET driver pathname |
*program | char pointer | input | ENET driver program name |
This function performs the following tasks:
1. Initializes the global pointers "ipptr", "dataptr", "cmdptr", "ackptr", "errorptr", and "statusptr."
2. Creates the ENET driver process.
3. Activates the ENET link.
int stop_enet(ushort linkid)
Parameter | Type | Use | Description |
---|---|---|---|
linkid | ushort | input | Link ID |
This function sends a deactivate, deinitialize, and terminate message to the ENET Driver process, which is indicated by linkid (the logical link number).
void init_linkmngr(void)
APP_ENET enet_mngr[], *mngrprt
This function initializes the link manager structures. The process IDs are initialized to 0 indicating that the process has not been created. The link state is set to deinitialized (LINK_DEINIT).
void process_cmd(int command, ushort linkid)
Parameter | Type | Use | Description |
---|---|---|---|
command | int | input | A valid ENET Driver command |
linkid | ushort | input | Link ID |
This function invokes a ENET Communications Driver "command." The commands used by this function are as follows:
CREATE_DRVR
TERM_DRVR
LINK_INIT
LINK_DEINIT
LINK_ACTIVATE
LINK_DEACTIVATE
GET_STATUS
SEND_PARAMS
SHOW_LINKS
This function calls "create_drvr()," "terminate_drvr()," "send_drvr_cmd()," and "show_process()." The Link ID should reflect the logical link you want the command to operate on.
void send_drvr_cmd (byte command, ushort linkid)
Parameter | Type | Use | Description |
---|---|---|---|
command | byte | input | A valid command packet identifier |
linkid | ushort | input | Link ID of driver process |
This function sends "commands" to the ENET Communications Driver process. The commands sent by this function are as follows:
LINK_INIT
LINK_DEINIT
LINK_ACTIVATE
LINK_DEACTIVATE
GET_STATUS
SEND_PARAMS
This function calls "get_qpkt()" to prepare the command Q_PKT, and then send Q_PKT by calling "send_toq()."
void create_drvr(ushort linkid, char *path, char *name)
Parameter | Type | Use | Description |
---|---|---|---|
linkid | ushort | input | Link ID of driver process |
*path | charpointer | input | "./enetdrvr" for ENET (or file name and directory path) |
*name | charpointer | input | "enetdrvr" for ENET |
This function creates the ENET Communications Driver process, sets up the communication queue, and updates the link manager data structure.
void show_process(ushort linkid)
Parameter | Type | Use | Description |
---|---|---|---|
linkid | ushort | input | Link ID of driver process |
Displays the attributes of the running process associated with the logical link number. The process ID of the ENET Communications Driver process, source and destination communication queue names, respective file descriptors, and the state of the link are shown.
int enet_read(int linkid, unchar *buf, int *len)
Q_PKT *ipptr
Parameter | Type | Use | Description |
---|---|---|---|
linkid | int | input | ENET Driver/link identifier |
buf | pointer, unsigned char | input | Receive buffer |
len | pointer, int | input | Maximum length (in bytes) of "buf" |
len | pointer, int | output | Actual length of received data |
This function performs the following functions:
int enet_write(int linkid, unchar *buf, int len)
Q_PKT *ipptr
Parameter | Type | Use | Description |
---|---|---|---|
linkid | int | input | ENET Driver/link identifier |
buf | pointer, unsigned char | input | Transmit buffer |
len | int | input | Length (in bytes) of "buf" |
This function performs the following functions:
int makefifo(char *path)
Parameter | Type | Use | Description |
---|---|---|---|
*path | char | input | FIFO pathname |
Communication is facilitated between the host application and the ENET Communications Driver via a data packet passing scheme involving two FIFOs: a read FIFO and a write FIFO. This function creates the FIFO indicated by "path" and returns the value from the mknod (make node) call.
char *fifoname(char *prefix, long key)
Parameter | Type | Use | Description |
---|---|---|---|
*prefix | char | input | Always "src_" for host's read FIFO and "dst_" for its write FIFO. |
key | long | input | The process ID of the associated ENET driver. |
This function creates a file name for a FIFO using prefix and key arguments. These arguments are preceded by "/tmp/" in the FIFO name. This function returns the file name of the desired FIFO.
void terminate_drvr(ushort linkid)
Parameter | Type | Use | Description |
---|---|---|---|
linkid | ushort | input | Link ID of driver process |
Used by the host application to terminate the communication driver process associated with the link ID. The driver process closes the socket and FIFO communications and then ends.
Note The ENET Communications Driver is accessed via the ENET Link Manager. The descriptions that follow are provided for informational purposes. This module also uses all the data structures found in "enet_if.h." |
File Name: | enet.h |
|
/* structure for host side global daa */
| ||
typedef struct {
| ||
| char
char
int
int
int
int
| read_fifo_name [256];
write_fifo_name [256];
read_fifo_fd;
write_fifo_fd;
link_no;
connected
|
}HOST;
|
|
|
/* structure for Ethernet side global data */
| ||
typedef struct {
|
| |
| char
char
int
int
int
| name [256];
official_name [256];
local _port;
remote_port;
status;
|
} LINK;
|
|
|
/* structure for this application global data */
| ||
typedef struct {
|
| |
| int
char
int
char
| pid;
LogFile [256];
LogLevel;
cfg_name [256];
|
} DRVR;
|
|
|
typedef char string 10 [11];
|
/* |
|
|
| host message structures | |
This is the set of possible host application data structures which may be used to transfer data to and from the interface manager. | ||
/*
|
|
|
enum host_message_types { | ||
| SDS_RECORD, | /* the host application uses SDS message record */ |
};
/* |
|
|
| link_type |
|
This is the set of possible SDA interfaces, or links, which may be used to connect to the switch. | ||
*/ |
|
|
enum link_type {
|
| |
| CLOSED,
| /* the link is not open */
|
| TCP_LINK
| /* TCP_IP socket */
|
}; |
|
|
#define BROADCAST_BCA 0xDF
#define MAX_MESSAGE_LEN 512
#defineMIN_ADLC_PACKET 6
#define MIN_MESSAGE_LEN 6 |
| |
#define NET_SIDE_A
#define NET_SIDE_B
#define HOST_CMD_A2
#define HOST_RPT_A
| 0
1
2
3
| |
/* received message states */ | ||
#define MSG_NOTOK0
#define MSG_OK
#define ACCEPT_MSG
#define NO_SPACE
| 0
1
2
3
| |
/* the data structure of the transfer buffer */
| ||
typedef struct
|
| |
| unsigned short length;
unsigned char data | /* message length */
/* message date*/
|
}
tcp_xfr_type;
|
|
|
typedef unsigned char byte_array [MAX_MESSAGE_LEN];
| /* the raw data */
|
typedef union xbfr {
|
| |
| tcp_xfr_type tcp;
| /* TCP message */
|
| byte _array raw;
|
|
{ msg_buffer_type;
|
| |
#define A_SIDE_ACTIVE 0x01
#define B_SIDE_ACTIVE 0x03
#define A_SIDE_STANDBY 0x00
#define B_SIDE_STANDBY 0x02 |
| |
/* network status values */
#define NOTOK
#define OK
#define LINK_IS_BROKEN
#define LRC_CHECK_ERROR
#define LINK_LOGIC_ERROR
#define INVALID_LINK_TYPE
#define TOO_MANY_RETRIES
#define MESSAGE_CHECK_ERROR
#define NO_HOST_APPLICATION
#define MAX_MSG_SIZE
|
0
1
-1
-2
-3
-4
-5
-6
-7
256
| |
extern int Log_Level;
| /* The amount of logging performed */
| |
extern int errno;
|
|
The ENET Communications Driver Process, enetdrvr, consists of 28 functions in 5 source code modules: control.c, datapath.c, enetdrvr.c, host.c, and network.c.
The following are the function names, synopsis and global data in the control.c file.
char *fifoname, int read_configuration, int get_token, print_structs
#include <stdio.h>
#include <fcntl.h>
#include <poll.h>
#include <malloc.h>
#include "types.h"
#include "enet.h"
int read_configuration();
int get_token();
void print_structs();
char *fifoname();
extern HOST
extern LINK
extern DRVR
extern struct poll fd
| host;
link [ ];
drvr;
connection [ ];
|
The following are the function names, synopsis and global data in the datapath.c file.
process_report, data_path_control, stop_data_path_control
#include <stdio.h>
#include <errno.h>
#include <poll.h>
#include <sys/time.h>
#include "enet.h"
#include "types.h"
#include "enet_if.h"
#define POLL_TIMEOUT
| 1000
process_report ( );
data_path_control ( );
stop_data_path_control ( );
check (report);
|
extern HOST host;
extern LINK link[];
extern DRVR drvr;
extern char LogStr[];
extern int shut_down;
extern int active_network;
extern struct pollfd connection[4];
extern Q_PKT ipdata, *ipptr;
The following are the function names, synopsis and global data in the enetdrvr.c file.
main
#include <stdio.h>
#include <signal.h>
#include <poll.h>
#include <fcntl.h>
#include "enet.h"
#include "types.h"
#include "enet_if.h"
/* function prototypes */
| ||
| int main( );
| |
/* external function prototypes */
| ||
| int
int
void
| parse_arguments ( );
data_path_control ( );
stop_data_path_control ( );
|
HOST host;
LINK link[2];
DRVR drvr;
Q_PKT ipdata, *ipptr;
DATA_PKT thisdata, *dataptr;
CMD_PKT thiscmd, *cmdptr;
ACK_PKT thisack, *ackptr;
ERROR_PKT thiserror, *errptr;
LINK_STATS thisstatus, *statptr;
PARAMS paras, *paraptr;
The following are the function names, synopsis and global data in the host.c file.
handle_que, send_toque, ack_toque, error_toq, stat_toq, setup_que, read_que, close_host
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stropts.h>
#include <poll.h>
#include <sys/types.h>
#include "enet.h"
#include "types.h"
#include "enet_if.h"
#define MAX_QTRIES
| 10
| /* max attempts to open fifos */
|
/* function prototypes */
| ||
| int
int
void
void
void
int
int
int
| handle_que( );
send_toque( );
ack_toque( );
error_toq( );
stat_toq( );
setup_que( );
read_que( );
close_host( );
|
/* external function prototypes */
| ||
| extern char *fifoname();
|
extern HOST
extern LINK
extern DRVR
extern Q_PKT
extern DATA_PKT
extern CMD_PKT
extern ACK_PKT
extern ERROR_PKT
extern LINK_STATS
extern PARAMS
| host;
link[];
drvr;
ipdata,*ipptr;
thisdata,*dataptr;
thiscmd,*cmdptr;
thisack,*ackptr;
thiserror,*errptr;
thisstatus,*statptr;
paras, *paraptr;
|
The following are the function names, synopsis and global data in the network.c file.
print_netstat, print_sockaddr, open_network, open_network_link,reopen_network_link, close_network, close_network_link,read_network_link, write_network_link, network_receive, pass_to_network, check_report
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <termio.h>
#include <poll.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "types.h"
#include "enet_if.h"
#include "enet.h"
typedef unsigned char link_packet[258];
|
|
typedef struct sockaddr_in SOCK_INET;
| /*just a typedef of sockaddr_in */
|
/* function prototypes */
| |
| void print_netstat( );
void print_sockaddr( );
int open_network_link( );
void reopen_network_link( );
int close_network_link( );
int read_network_link( );
int write_network_link( );
int open_network( );
int close_network( );
int network_receive( );
int pass_to_network( );
int check_report( );
|
/* external function prototypes */
| |
| int get_token ();
|
extern HOST host;
extern LINK link[2];
extern DRVR drvr;
extern char LogStr[];
extern int shut_down;
extern int link_debug;
extern int active_network;
char *fifoname(char *prefix, longkey)
Parameter | Type | Use | Description |
---|---|---|---|
*prefix | char | input | A character string to prefix the file name |
key | long | input | A unique ID for this file name |
This function returns a file name for the FIFO using the prefix and key arguments. The prefix argument is always either "src_" for the host applications read FIFO, or "dst_" for the host applications write FIFO. The key argument is the process ID number for the associated communications driver. These arguments are preceded by "/tmp" in the FIFO name. This function returns a pointer to the character string containing the file name.
int read_configuration(char *name)
Parameter | Type | Use | Description |
---|---|---|---|
*name | char | input | A valid UNIX file name |
This function reads the configuration file which is pointed to by "name." The specified items in the configuration file are read in to the appropriate global variables contained in the driver program.
This function returns 0 (TRUE) if the file exists and contains valid data, -1 (FALSE) if the file does not exist or the data contained in the file is invalid.
int get_token(FILE *fil, char *tok, int siz)
Parameter | Type | Use | Description |
---|---|---|---|
*fil | char pointer | input | An opened file pointer |
*tok | char pointer | input | Return value of the next token read |
siz | int | input | Size of the token |
This function is used by "read_configuration" to read individual portions of the configuration file.
This function returns the following values:
void print_structs(void)
This function prints the contents of the three major structures (extern HOST, extern LINK, and extern DRVR) of the ENET Communications Driver process to standard output.
void process_report(int net, unsigned char *msg, int len)
Parameter | Type | Use | Description |
---|---|---|---|
net | int | input | The network from which the report came |
*msg | uchar | input | Pointer to the report data |
len | int | input | Length of report data |
This function takes an incoming report from the VCO/4K and sends it to the application by placing it in the FIFO. This function also checks for redundant switchover and adjusts its global variables so future commands are sent to the correct TCP link.
int data_path_control(void)
This function polls the TCP and FIFO links for data awaiting processing. If there is data on the link, this function calls the appropriate functions to parse and send the data to its destination. Polling is continuous as long as the global "shut_down" variable is set to -1 (FALSE).
This function always returns 0 (TRUE).
void stop_data_path_control(int sig, int code, struct sigcontext *scp, char *addr)
Parameter | Type | Use | Description |
---|---|---|---|
sig | int | input | Information sent by the signal handler |
code | int | input | Information sent by the signal handler |
*scp | struct sigcontext | input | Information sent by the signal handler |
*addr | char | input | Information sent by the signal handler |
This function is used for the three UNIX signals that are caught and processed by the driver process (SIGTERM, SIGQUIT, and SIGINT). It sets the global "shut_down" variable to 0 (TRUE), which sets up a graceful shutdown of the driver.
int main(int argc, char**argv)
Parameter | Type | Use | Description |
---|---|---|---|
argc | int | input | Standard C command line argument |
**argv | char | input | Standard C command line argument |
This function is the main function of the enetdrvr process. It is responsible for initializing global variables, setting up the signal handlers and starting the polling loop. When the polling is complete, it shuts down the network and host connections and returns to the operating system.
This function returns the status of "data_path_control," which is always 0 (TRUE).
int handle_que(void)
This function is called by the polling rouine when data is available on the host applications output queue. This packet is read and the proper actions are taken depending on the type of packet sent. In general, a data packet contains a command to the VCO/4K, a command packet indicates the host wants the driver to perform a specific action.
This function returns either a valid pkt_type, or a NULL if nothing is read.
int send_toque(void)
This function writes the packet in the global Q_PKT ippr structure to the host applications FIFO queue.
This function returns OK if the data is written. Otherwise, NOTOK.
void ack_toque(byte ack)
Parameter | Type | Use | Description |
---|---|---|---|
ack | byte | input | One of the valid commands (PORT_INT, PORT_DEINT, etc.) |
This function is used by the ENET Communications Driver software to send an ACK packet to the host application. ACK packets are sent to acknowledge to the host application that its command was carried out.
void error_toque(byte ack)
Parameter | Type | Use | Description |
---|---|---|---|
error | ushort | input | A valid error code |
This function is used by the ENET Communications Driver software to send an error packet to the host application. An error packet is sent to notify the applications that a command it sent has failed. Valid error packet types can be found in enet_if.h.
void stat_toq(void)
This function is used by the ENET COmmunications Driver to send statistics about its links to the host applications process in response to a SEND_STATS command. Statistics are reset to zero (and begin accumulating again) after they are sent to the host applications.
int setup_que(void)
This function instructs the ENET Communications Driver to open the host applications FIFOs for reading and writing. The queues must have been created by the host application prior to calling this function.
This function returns OK if the queue is opened successfully. Otherwise, NOTOK.
int read_que(void)
This function is used by the ENET Communications Driver to read one packet from the host application's output queue. It is used internally by "handle_que."
This function returns DONE if data has been read. Otherwise, NULL.
int close_host(void)
This function is used to close the enetdrvr process connection to the host applications FIFOs. A message is sent to the log file to indicate this function has been called.
This function always returns 0.
void print_netstat(int network)
Parameter | Type | Use | Description |
---|---|---|---|
network | int | input | The network side for which the statistics are being displayed. |
This function is used to print the log file various statistics about the network TCP connection to standard output. The statistics include connection type, packets received, number of faults, reports received, average size, and number of link responses. "network" should indicate either NET_SIDE_A or NET_SIDE_B.
void print_sockaddr(SOCK_NET *sock, char *lab)
Parameter | Type | Use | Description |
---|---|---|---|
*sock | SOCK_NET | input | The socket for which the data is being printed |
*lab | char | input | Text label |
This function prints information about the specific socket into a log file. Information includes the family, port, and address of the socket. "lab" is a user-definable string, which adds information to the file output.
int open_network(int side)
Parameter | Type | Use | Description |
---|---|---|---|
side | int | input | The network side to open |
This function is used to set up the TCP sockets for the ENET Communications Driver to talk to the VCO/4K system. Two sides can be opened for redundant systems. (this feature is set in the configuration file.) "side" should indicate either NET_SIDE_A or NET_SIDE_B.
If this function is successful, a 0 is returned. Otherwise, a -1 is returned.
int open_network_link(int side, struct pollfd *pfd)
Parameter | Type | Use | Description |
---|---|---|---|
side | int | input | The network side to open |
*pfd | struct pollfd | input | The poll structure of the UNIX system |
This function is used internally by the open_network() to open the TCP links to the VCO/4K system. "*pfd" structure should be set up as indicated in he UNIX poll function intsructions. "side" should indicate either NET_SIDE_A or NET_SIDE_B.
If the function completes successfully, it returns the file ID. Otherwise, it returns a -1.
void repoen_network_link(int sig, int code, struct sigcontext *scp, char *addr)
Parameter | Type | Use | Description |
---|---|---|---|
*sig | int | input | Information sent by signal handler |
code | int | input | Information sent by signal handler |
*scp | struct | input | Information sent by signal handler |
*addr | char | input | Information sent by signal handler |
This function is called when the VCO/4K system sends a signal indicating that the TCP link is down. A 90-second signal alarm is sent to allow the Ethernet link on the VCO/4K system to reset. When the alarm is raised, it calls this function to attempt to reopen the link. If the link cannot be reopened, the link variables are cleared and a POLLING_FAIL error is sent to the host application.
int close_network(int side)
Parameter | Type | Use | Description |
---|---|---|---|
side | int | input | The network side to close |
This function is used to stop all communications from the ENET Communications Driver to the VCO/4K system. "side" should be either NET_SIDE_A or NET_SIDE_B.
If the network side is closed successfully, this function returns a 0. Otherwise, it returns a -1.
int close_network_link(struct pollfd *pfd)
Parameter | Type | Use | Description |
---|---|---|---|
*pfd | struct | input | The poll structure for the link |
This function is used internally by "close_network" to handle the mechanics of closing the network link.
If the link is closed successfully, this function returns a 0. Otherwise, it returns a -1.
int read_network_link(int fd, unsigned char *msg, int size)
Parameter | Type | Use | Description |
---|---|---|---|
fd | int | input | The file ID of the link |
*msg | uchar pointer | input | Pointer to the buffer which will receive the data |
size | int | input | The size of the buffer message |
This function is used internally by "network_receive." It handles the mechanics of reading data from the TCP link and storing it in a buffer for processing.
If the function completes successfully, it returns the number of bytes stored. Otherwise, it returns a -1.
int write_network_link(int fd, unsigned char *msg, int size)
Parameter | Type | Use | Description |
---|---|---|---|
fd | int | input | The file ID of the link |
*msg | uchar pointer | input | Pointer to the buffer from which to write |
size | int | input | The number of bytes from the buffer to write |
This function writes "size" number of bytes from the msg buffer to the VCO/4K system which is pointed to by the fd descriptor.
If the function completes successfully, it returns 0. Otherwise, it returns a -1.
int network_receive(int network, unsigned char *message, int size)
Parameter | Type | Use | Description |
---|---|---|---|
network | int | input | The network side from which to read |
*message | unsigned char | input | The buffer that will hold the data read |
size | int | input | The size of the buffer |
This function transfers a single report from the VCO/4K system into the buffer pointed to by "*message." "network" should indicate either NET_SIDE_A or NET_SIDE_B.
This function returns one of the following values:
int pass_to_network(int network, unsigned char *message, int length)
Parameter | Type | Use | Description |
---|---|---|---|
network | int | input | The network side to which to write |
*message | unsigned char | input | The buffer containing the data to write to the VCO/4K system |
length | int | input | The number of bytes to write to the message buffer |
This function writes a command to the VCO/4K system indicated by "network." Before sending the message, this function checks the length of the message. If the message is too long for the buffer, the message is not sent. The function does not perform any other tasks on the message; it is sent unchanged. "side" should indicate either NET_SIDE_A or NET_SIDE_B.
This function returns one of the following values:
int check_report(int network, unsigned char *msg_data, int size)
Parameter | Type | Use | Description |
---|---|---|---|
network | int | input | The network side from which the report data is collected |
*msg_data | unsigned char | input | The buffer which will hold the report |
size | int | input | The size of the msg_data buffer |
This function checks the VCO/4K system pointed to by "network" to see if data is available. "side" should indicate either NET_SIDE_A or NET_SIDE_B.
If this function is successful, it returns the number of bytes received from the VCO/4K. If an error occurs, the function returns a 0 or a -1.
This module uses the same data structures and constants as the ENET Link Manager.
The utilities module, enet_util.c, contains seven functions which are used by both the ENET Link Manager and ENET communications driver.
int logMsg(char *log_file, char *msg)
Parameter | Type | Use | Description |
---|---|---|---|
*log_file | char | input | A valid UNIX file name |
*msg | char | input | Text string to write to file |
This function attempts to open the file name passed in "*log_file" and then writes into the file the string pointed to by "*msg." This function is included for compatibility with the ADLC product.
If this function completes successfully, it returns 0. Otherwise, it returns -1.
unchar hex2ascii(unchar hexval)
Parameter | Type | Use | Description |
---|---|---|---|
hexval | unchar | input | A hexadecimal value |
This function returns the ASCII character equivalent to the value passed to it in "hexval." This function is included for compatibility with the ADLC product.
The ASCII equivalent of "hexval."
unchar ascii2hex(int asciival)
Parameter | Type | Use | Description |
---|---|---|---|
asciival | int | input | An ASCII character |
This function returns the hexadecimal value that is equivalent to the character passed to it in "asciival." This function is included for compatibility with the ADLC product.
The hexadecimal value of "asciival."
int str2hex(char *str, uchar *buf)
Parameter | Type | Use | Description |
---|---|---|---|
*str | char | input | A string of ASCII characters |
*buf | uchar | input | Returns the hexadecimal byte stream |
This function translates the ASCII string pointed to by "*str" into a hexadecimal byte stream. This function is included for compatibility with the ADLC product.
The number of bytes in the "buf" array.
char *hex2str(uchar *buf, int buflen)
Parameter | Type | Use | Description |
---|---|---|---|
*buf | uchar | input | The hexadecimal byte array |
buflen | int | input | Number of bytes to translate from "buf" |
This function translates the hexadecimal byte stream located in the buffer pointed to by "*buf" into an ASCII string. "buflen" specifies how many bytes in "buf" to translate. It inserts a blank character between every two digits in the output string. It calls the "malloc()" function to allocate space for the ASCII string.
This function returns a pointer to the ASCII string.
void show_qpkt(Q_PKT *qpktp)
Parameter | Type | Use | Description |
---|---|---|---|
*qpktp | Q_PKT | input | Packet to display |
This function displays the contents of the Q_PKT packet (pointed to by "*qpktp" and identified by the pkt_type member). It displays a detailed breakdown of the packet on the standard output.
void displayHex(uchar buf, int buflen)
Parameter | Type | Use | Description |
---|---|---|---|
buf | uchar | input | Buffer of byte stream to display |
buflen | int | input | Number of bytes to display |
This function displays on the standard output the ASCII representation of the hexadecimal byte stream pointed to by "buf" up to "buflen" bytes. It inserts a blank character after each displayed byte. This function is standard output to check its contents.
Posted: Fri Mar 2 16:53:39 PST 2001
All contents are Copyright © 1992--2001 Cisco Systems, Inc. All rights reserved.
Important Notices and Privacy Statement.