######################################################################
# Candidate for discovery_OCA module - Begin
######################################################################

######################################################################
#
# This defined constant is the key defining the OCA type which
# must be present in every OCA record.  The value
# of this key in the OCA  must be a member of the set defined here.
#
OCA_TYPE = "OCA_Type"

#####################################################################
#
# This is the set of valid Observed Comutation Action (OCA) Types and
# their associated arguments.
#
# Each OCA is represented by a dictionary with the specified set of
# keys. Every OCA defines one key: OCA_TYPE. This defines the type of
# action being observed. Most define OCA_ARG_PIDwhich provides the
# taking the observed action, respectively.

#####################################################################
# Root Thread
#   OCA_TYPE    : OCA_ROOT_THREAD
#   OCA_ARG_PID : <PID of acting thread> 
#
#   This "action" is used to announce/identify which thread is the
#   root of the "traceme" set. This should be the thread ` that will
#   do an exec on the "traced-cmd <traced-cmd-args>" provided as the
#   argument to "tracme". 
#
OCA_ROOT_THREAD     = "OCA First Generation"
OCA_ARG_GEN	    = "OCA Generation"
OCA_ARG_REL         = "OCA Relationship"
OCA_ARG_CLONE_FLAGS = "OCA Clone Flags"
OCA_ARG_PID         = "OCA AC PID"
OCA_ARG_AC_NAME	    = "OCA AC Name"
OCA_ARG_AC_ID	    = "OCA AC ID"
OCA_ARG_AC_TYPE	    = "OCA AC Type"



#####################################################################
# FORK
#   OCA_TYPE       : OCA_ROOT_THREAD
#   OCA_ARG_CHILD  : PID of created process
#   OCA_ARG_PARENT : PID of creating process
#
#   *** How to distinguish this from fork-kernel-thread and spawn an
#       additional pthread sharing the current address space is an open
#       question.
#
#   *** Perhaps we need N different instrumentations points, perhaps we
#       have only one but distinguish the cases using parameter
#       values. Study the situation and decide the best course.
#
OCA_FORK            = "OCA Fork"     
OCA_KERNEL_FORK     = "OCA KFork"     
OCA_SPAWN           = "OCA Spawn"
OCA_ROOT_FD         = "Root FD"
OCA_ARG_PARENT_ID   = "Parent ID"
OCA_ARG_PARENT_PID  = "Parent PID"
OCA_ARG_PARENT_NAME = "Parent Name"
OCA_ARG_PARENT_TYPE = "Parent Type"
OCA_ARG_CHILD_ID    = "Child ID"
OCA_ARG_CHILD_PID   = "Child PID"
OCA_ARG_CHILD_NAME  = "Child Name"
OCA_ARG_CHILD_TYPE  = "Child Type"
OCA_ARG_ORIGINAL_PARENT_PID = "Original Parent PID"
OCA_ARG_ORIGINAL_CHILD_PID = "Original Child PID"
OCA_ARG_CLONG_FLAGS = "Clone flags"

OCA_ARG_IN_FDS      = "OCA Inherited FDs"
OCA_ARG_IN_SHMS     = "OCA Inherited SHMs"

#####################################################################
# Exec
#   OCA_TYPE          : OCA_ROOT_THREAD
#   OCA_ARG_PID       : <PID of acting thread> 
#   OCA_ARG_PROG_NAME : <string argument specifying absolute or relative path>
#   OCA_ARG_PROG_ARGS : <string specifying program arguments>
#
# This action notes that the acting thread is becoming the image of
# the specified program, executed with the specified arguments
#
OCA_EXEC          = "OCA EXEC" 
OCA_ARG_EXEC_NAME = "Exec Name"
OCA_ARG_EXEC_ARGS = "Exec Args"

#####################################################################
# Signal Send
#   OCA_TYPE              : OCA_SIGNAL_SEND
#   OCA_ARG_SENDER        : <PID of sending process> 
#   OCA_ARG_RECEIVER      : <PID of receiving process>
#   OCA_ARG_SIGNAL_NUMBER : <Number of signal being sent>
#
# This OCA is generated by the sender, and describes the receiver and
# the signal number being sent. Delivery is determined by when the
# receiving process next executes.
#
OCA_SIGNAL_SEND        = "OCA Signal SEND"   
OCA_ARG_SENDER         = "Sender"
OCA_ARG_RECEIVER       = "Receiver"
OCA_ARG_SIGNAL_NUMBER  = "Signal Number"

#####################################################################
# Signal Receive
#   OCA_TYPE    : OCA_SIGNAL_RECEIVE
#   OCA_ARG_PID : <PID of acting thread> 
#   OCA_ARG_SIGNAL_NUMBER : <Number of signal being received>
#
# This OCA describes the act of receiving a signal. This OCA may not
# be necessary for discovery of computation strucute, but is provided
# for completeness, and because other kinds of analysis of computation
# actions may be worthwhile, beyond basic discovery.
#
OCA_SIGNAL_RECEIVE = "OCA Signal Receive"   

#####################################################################
# Shared Memory Get
#   OCA_TYPE          : OCA_SHM_GET
#   OCA_ARG_PID       : <PID of acting thread> 
#   OCA_ARG_SHM_ID    : <int ID for shared segment, -1 on error> 
#   OCA_ARG_SHM_KEY   : <key value used to identify shm segment>
#   OCA_ARG_SHM_SIZE  : <size of segment requested >
#   OCA_ARG_SHM_FLAGS : <Flag arguments provided>
#
# This provides a unique ID associated with the shared segment
# identified by the key. The segment is not yet attached to the
# address space of the process, but the handle returned is required to
# achieve that attachment.
#
OCA_SHM_GET       = "OCA SHM GET" 
OCA_ARG_SHM_ID    = "SHM ID"
OCA_ARG_SHM_KEY   = "SHM KEY"
OCA_ARG_SHM_SIZE  = "SHM Size"
OCA_ARG_SHM_FLAGS = "SHM FLAGS"


#####################################################################
# Shared Memory Attach
#   OCA_TYPE           : OCA_SHM_ATTACH
#   OCA_ARG_PID        : <PID of acting thread> 
#   OCA_ARG_SHM_ID     : <Integer identifying shared segment> 
#   OCA_ARG_SHM_ADDR   : <address within process addr space requested >
#   OCA_ARG_SHM_FLAGS  : <Flag arguments provided>
#   OCA_ARG_SHM_RETURN : <should be attachment address, -1 on error>
#
# This action attaches the specified segment at the requested address.
# How these basic semantics are affected by the flags is not yet
# clear.
#
OCA_SHM_ATTACH       = "OCA SHM Attach" 
OCA_ARG_SHM_ADDR     = "SHM Addr"
OCA_ARG_SHM_NAME     = "SHM Name" 

#####################################################################
# Shared Memory Detach
#   OCA_TYPE           : OCA_SHM_DETACH
#   OCA_ARG_PID        : <PID of acting thread> 
#   OCA_ARG_SHM_ADDR   : <address within process addr space at which segment is attached >
#   OCA_ARG_SHM_RETURN : <0 on success, -1 on error>
#
# This action describes the detaching of a the segment currently
# attached to the process address space at the specified address. If
# it succeeds, it returns, 0, and on error it returns -1.
#
OCA_SHM_DETACH  = "OCA SHM Detach"
OCA_SHMAT_ADD	= "OCA Shmat Add"

#####################################################################
# PC operations
#
OCA_OPEN	 = "OCA Open"
OCA_CLOSE	 = "OCA Close"
OCA_READ	 = "OCA Read"
OCA_WRITE	 = "OCA Write"

OCA_READV	 = "OCA ReadV"
OCA_WRITEV	 = "OCA WriteV"
# PC Types for OCA events. The type may be unknown if a nonfamilial
# AC issues the OCA event.
#

#####################################################################
# Pipe Create
#   OCA_TYPE         : OCA_PIPE_CREATE
#   OCA_ARG_PID      : <PID of acting thread> 
#   OCA_ARG_FD_READ  : <file descriptor for read end of pipe>
#   OCA_ARG_FD_WRITE : <file descriptor for write end of pipe>
#   OCA_ARG_PIPE_ID  : <unique pipe descriptor, possibly (file-system, inode)
#
# This act describes creating a pipe, which has read and write ends
# each attached to file descriptors in this process. It is not known
# at this time if the unique identifier of a regular pipe is the same
# for that of a namd pipe, or different.
#
OCA_PIPE_CREATE  	= "OCA Pipe Create"
OCA_ARG_FD_READ  	= "FD Read"
OCA_ARG_FD_WRITE 	= "FD Write"
OCA_ARG_READ_INODE_ID	= "Read Inode ID"
OCA_ARG_WRITE_INODE_ID	= "Write Inode ID"

#####################################################################
# Named Pipe Open
#   OCA_TYPE          : OCA_NP_OPEN

OCA_ARG_PIPE_NAME  = "Pipe Name"
OCA_ARG_MODE       = "Mode"
OCA_ARG_MODE_READ  = "Pipe Read Mode"
OCA_ARG_MODE_WRITE = "Pipe Write Mode"
OCA_ARG_FD         = "File Descriptor"


#####################################################################
# File Locking
#   OCA_TYPE          : OCA_REGULAR_FILE

OCA_FCNTL_LOCK    = "OCA FCTL Lock" 
OCA_FCNTL_UNLOCK  = "OCA FCTL Unlock"
OCA_LOCKED_WRITE  = "OCA Locked Write"
OCA_LOCKED_READ   = "OCA Locked Read"

###################################################################
# Some constants defined for sys_open(),sys_close(),sys_read(),sys_write()
# system calls

OCA_ARG_PC_ID		= "PC ID"
OCA_ARG_PC_NAME		= "PC Name"
OCA_ARG_PC_TYPE		= "PC Type"
OCA_READ_WRITE_DATA	= "Read/Write Data"
OCA_ARG_SIZE		= "Size"

#####################################################################
# Sockets
OCA_SOCKET_CREATE	= "Socket Open"
OCA_SOCKET_ACCEPT 	= "Accept"
OCA_SOCKET_CONNECT 	= "Connect"
OCA_SOCKET_BIND 	= "Socket Bind"
OCA_SOCKET_LISTEN 	= "Listen"
OCA_SOCKET_ADD		= "Socket Add"

OCA_SOCKET_SEND_TO 	= "Socket SYS_SENDTO"
OCA_SOCKET_RECV_FROM 	= "Socket SYS_RECVFROM"
OCA_SOCKET_SEND_MSG 	= "Socket SYS_SENDMSG"
OCA_SOCKET_RECV_MSG 	= "Socket SYS_RECVMSG"

OCA_ARG_SOCK_NAME 	= "Socket Name"
OCA_ARG_BOUND_ID 	= "Bound ID"
OCA_ARG_BACKLOG 	= "Backlog Size"
OCA_ARG_FAMILY		= "Socket Family"
OCA_ARG_SOCK_ID		= "Socket ID"

#####################################################################
# Ptrace
# OCA_TYPE		: OCA_PTRACE
# OCA_ARG_CALLER_PID	: PID of process that called ptrace
# OCA_ARG_REQUEST	: Request flags argument
# OCA_ARG_PID		: PID argument
# OCA_ARG_ADDR		: Addr argument
# OCA_ARG_DATA		: Data argument
# OCA_ARG_RET		: Return value

OCA_PTRACE_ATTACH	= "Ptrace Attach"
OCA_PTRACE_DETACH	= "Ptrace Detach"
OCA_PTRACE_CONTROL	= "Ptrace Control"
OCA_PTRACE_MASTER	= "Ptrace Master"
OCA_PTRACE_SLAVE	= "Ptrace Slave"
OCA_PTRACE_MASTER_ID	= "Ptrace Master ID"
OCA_PTRACE_MASTER_TYPE	= "Ptrace Master Type"
OCA_PTRACE_MASTER_NAME	= "Ptrace Master Name"
OCA_PTRACE_SLAVE_ID	= "Ptrace Slave ID"
OCA_PTRACE_SLAVE_NAME	= "Ptrace Slave Name"
OCA_PTRACE_SLAVE_TYPE	= "Ptrace Slave Type"
OCA_ARG_REQUEST 	= "Ptrace Request"
OCA_ARG_ADDR 		= "Ptrace Addr"
OCA_ARG_DATA 		= "Ptrace Data"
OCA_ARG_RET 		= "Return value"

# Used to announce and rename DSUI threads
OCA_DSUI_THREAD_BUFFER         = "DSUI Buffer Thread"
OCA_DSUI_THREAD_LOGGING        = "DSUI Logging Thread"
OCA_DSUI_THREAD_SIGNAL_CATCHER = "DSUI Signal Catcher"
# 
OCA_DSUI_BUF = "DSUI Buffer"
OCA_DSUI_LOG = "DSUI Logger"
OCA_DSUI_SIG = "DSUI Signal"

# Context switch events
OCA_SWITCH_TO	  = "Switch to"
OCA_SWITCH_FROM	  = "Switch from"
OCA_ARG_PREEMPTED = "Was Preempted"

# Useful for client / server analysis
OCA_UNRELATED_CLIENT_CONN = "Unrelated Client Connection"

#####################################################################
# IP for all System Calls
OCA_SYSCALL	= "System Call"
OCA_ARG_SYSCALL = "Syscall Number"
OCA_ARG_PARAMS  = "Parameters"

#####################################################################
# Active Component Attributes
# AC_ATTR_OCA_PID	: OCA pid of this AC (generated by
#			  OCA_event_maker)
# AC_ATTR_ORIG_PID	: Original pid (could be called TID as this
#			  corresponds to the thread id, not the
#			  thread group id)
# AC_ATTR_NAME		: A string name given to this AC
# AC_ATTR_FDS		: A reference to a dict indexed by the file
#			  descriptors in this AC's file descriptor
#			  table
# AC_ATTR_SHMIDS	: A reference to a dict indexed by the shmids
#			  this AC is known to have access to
# AC_ATTR_EXEC_NAME	: The name of the program that was execed by
#			  this AC if it is known
# AC_ATTR_RELATION	: The relationship this AC has to the 
#			  computation as a whole (i.e. why the AC was
# 			  added to our computation set)
# AC_ATTR_GENERATION	: The generation in our computation this
#			  AC was added to our records. This number is
#			  only incremented when ACs are forked

AC_ATTR_OCA_PID		= "AC OCA PID"
AC_ATTR_AC_ID		= "AC ID"
AC_ATTR_ORIG_PID	= "AC Original PID"
AC_ATTR_NAME		= "AC Name"
AC_ATTR_FDS		= "AC File Descriptors"
AC_ATTR_SHMATS		= "AC Attached SHM Addresses"
AC_ATTR_EXEC_NAME	= "AC Exec Filename"
AC_ATTR_RELATION	= "AC Relation"
AC_ATTR_GENERATION	= "AC Generation"
AC_ATTR_MASTERS		= "AC Ptrace Masters"
AC_ATTR_SLAVES		= "AC Ptrace Slaves"
AC_ATTR_FILE_GID	= "AC File GID"
AC_ATTR_SHM_GID		= "AC SHM GID"
AC_TG_ALIVE		= "AC Alive"
AC_TG_EXITED		= "AC Exited"

AC_FAMILIAL_TASK	= "AC Familial Task"
AC_ROOT_RECORD		= "AC Root Record"
AC_INIT_BASH		= "AC Init Bash"
AC_NONFAMILIAL_TASK	= "AC Nonfamilial"
AC_SIGNAL_REL		= "AC Received Signal"
AC_SOCKET_REL		= "AC Socket Relation"
AC_SHMEM_REL		= "AC SHMEM Relation"

AC_TYPE			= "AC Type"
AC_UTHREAD		= "AC User Thread"

AC_REF_ID		= "AC Ref ID"
AC_REF_MODE		= "AC Ref Mode"
AC_REF_READ		= "AC Bytes Read"
AC_REF_WROTE		= "AC Bytes Written"

# Exec name for AC's which have not issued an exec call and  are not 
# familially related to an AC which has
AC_DEFAULT_EXEC_NAME	= "No exec"
 
#####################################################################
# Active Component Attributes
# PC_ATTR_PC_ID		: (System ID, Inode ID) of this PC
# PC_ATTR_AC_REFS	: Open AC references to this PC. Currently
#			  expressed as a list of open 
# 			  (PID, File Descriptor) pairs

PC_ATTR_PC_ID		= "PC_ID (SysID, InodeID)"
PC_ATTR_OPEN_REFS	= "AC Open Refs (PID, FD)"
PC_ATTR_CLOSED_REFS	= "AC Closed Refs (PID, FD)"
PC_ATTR_NAME		= "Name"
PC_ATTR_LOCKED		= "File locked"
PC_ATTR_SOCKET_NAME 	= "socket"
PC_ATTR_AC_REF		= "AC Ref"

PC_TYPE			= "PC Type"

PC_FIFO			= "Named Pipe"
PC_PIPE			= "Pipe"
PC_SHM  		= "Shared Memory"
PC_FILE			= "File"
PC_SK_ENDPOINT		= "Socket Endpoint"
PC_KERNEL_SOCKET	= "Kernel Socket"
PC_SOCKET		= "Socket "
PC_PSEUDOT		= "Psuedo Terminal"
PC_SEM			= "IPC Semaphore"
PC_UNKNOWN		= "Unknown"

PC_PIPE_FS		= "pipefs"
PC_SOCKET_FS		= "sockfs"
PC_DEVPTS_FS		= "devpts"
PC_NULL_FILE		= "Null File"

PC_SKAT_STATE		= "Socket State"
PC_SKAT_BACKLOG		= "Socket Backlog Size"
PC_SKAT_BOUND_ID	= "Socket Bound ID"
PC_SKAT_NAME		= "Connected Socket Name"
PC_SKAT_OTHER_END	= "Other End ID"

OCA_TNAME_BASE 	  	= "T%d"
PC_PIPE_NAME_BASE	= "P%d"
PC_SHM_NAME_BASE	= "SHM%d"
PC_PT_NAME_BASE		= "PT%d"
OCA_PID_CREATE		= True
OCA_PID_NO_CREATE	= False	

OCA_SK_END_BASE		= "SK_EP %d"
OCA_SKNAME_BASE 	= "SK %d"
OCA_KSNAME_BASE    	= "Kernel Socket %d"
AC_REF_SOCKET_NAME	= "Socket Name"
AC_REF_DEST_INFO	= "Dest Port/IP"
AC_REF_SRC_INFO		= "Src Port/IP"


# Socket States
SK_FREE			= "Free"
SK_BOUND		= "Bound"
SK_LISTENING		= "Listening"
SK_CONNECTED_SERVER	= "Connected Server"
SK_CONNECTED_CLIENT	= "Connected Client"

SK_UNBOUND		= "Unbound"
SK_UNASSIGNED		= "Unassigned"

TG_DEAD_THREADS		= "Dead Threads"
TG_ALIVE_THREADS	= "Alive Threads"

MIN_PRINT_LEVEL 	= 1
RAW_INFO_PRINT		= 2
REG_FILE_PRINT		= 3
MAX_PRINT_LEVEL		= 4

###########################################################
####     Java Virtual Machine Components ##################
###########################################################

OCA_JAVA_WRAPPER = "Java Wrapper"
OCA_JAVA_WRAPPER_NAME = "Wrapper"
OCA_JAVA_VM_THREAD = "Java VM"
OCA_JAVA_VM_THREAD_NAME = "VM"
OCA_JAVA_WATCHER = "Java Watcher"
OCA_JAVA_WATCHER_NAME = "Watcher"
OCA_JAVA_THREAD = "JAVA Thread(unknown) "
OCA_JAVA_NATIVE = "Java Native"
OCA_JAVA_NATIVE_NAME = "Native "
OCA_JAVA_COMPILER = "Java Compiler"
OCA_JAVA_COMPILER_NAME = "Compiler "
OCA_JAVA_SIGNAL_DISPATCHER = "Java Signal"
OCA_JAVA_SIGNAL_DISPATCHER_NAME = "Signal "
OCA_JAVA_GC = "Java GC"
OCA_JAVA_GC_NAME = "GC "
OCA_JAVA_MEMORY_DETECTOR = "Java Low Memory Detector"
OCA_JAVA_MEMORY_DETECTOR_NAME = "Low Memory Detector "
OCA_JAVA_ATTACH_LISTENER = "Attach Listener"
OCA_JAVA_ATTACH_LISTENER_NAME = "Attach Listener "


##########################################################
####   SHARED FILE INFORMATION ###########################
##########################################################

OCA_SHARED_FILE_OPEN = "SHARED File Open"
OCA_SHARED_FILE_CLOSE = "SHARED File Close"
OCA_SHARED_FILE_READ = "SHARED File Read"
OCA_SHARED_FILE_WRITE = "SHARED File Write"


# OCA_X    = "OCA X" 
# OCA_X    = "OCA X" 
# OCA_X    = "OCA X" 
#
#
# OCA_ARG_NP_ID      = "NP ID"
# OCA_ARG_X          = "X"
# OCA_ARG_X          = "X"
# OCA_ARG_X          = "X"
# OCA_ARG_X          = "X"
# OCA_ARG_X          = "X"
#
# -----------------------------------------------------------------------
#
# - FILE LOCK
#   - flock 
#     - Lock
#       - PID
#       - Path Name
#       - (file-system, file Inode)  
#       - Handle??
#     - Unlock 
#       - PID
#       - Path Name ??
#       - (file-system, file Inode)  
#       - Handle??
#   - fcntl 
#     - Lock
#       - PID
#       - Path Name
#       - (file-system, file Inode)  
#       - Handle??
#     - Unlock 
#       - PID
#       - Path Name ??
#       - (file-system, file Inode)  
#       - Handle??
#
# -----------------------------------------------------------------------
#
# - Semaphores
#   - Attach
#     - PID
#     - Path name string
#     - handle/FD
#
#   - Detach
#     - PID
#     - Handle/FD
#
#   - Lock
#     - PID
#     - Handle/FD
#
#   - Unlock
#     -PID
#     - Handle/FD
#
# -----------------------------------------------------------------------
#
# - Sockets
#   - Create
#     - PID
#     - FD
#     - INODE ID??
#   - Bind
#     - PID
#     - FD
#     - INODE ID??
#   - Listen
#     - PID
#     - FD
#     - INODE ID??
#   - Accept
#     - Accepting PID
#     - Accepting FD
#     - Accepting PORT
# Used to match this up with the name it will replace
OCA_ARG_OLD_NAME = "Old name" 
####################################################################
#SOCKETS

