masteriolib.html

来自「vxworks相关论文」· HTML 代码 · 共 541 行 · 第 1/2 页

HTML
541
字号
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/masterIoLib.html - generated by refgen from masterIoLib.c --> <title> masterIoLib </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.html"><i>VxWorks Reference Manual :  Libraries</i></a></p></blockquote><h1>masterIoLib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>masterIoLib</strong> - default IO routines for the SNMP master agent </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><i><a href="./masterIoLib.html#masterIoInit">masterIoInit</a></i>(&nbsp;)</b>  -  create the IPC mechanism at the SNMP master agent<br><b><i><a href="./masterIoLib.html#snmpMonitorSpawn">snmpMonitorSpawn</a></i>(&nbsp;)</b>  -  spawn <b>tMonQue</b> to run <b><i>snmpQueMonitor</i>(&nbsp;)</b><br><b><i><a href="./masterIoLib.html#masterIpcComp">masterIpcComp</a></i>(&nbsp;)</b>  -  transmit a completion of transmission message<br><b><i><a href="./masterIoLib.html#masterIoWrite">masterIoWrite</a></i>(&nbsp;)</b>  -  send the encoded buffer to the subagent<br><b><i><a href="./masterIoLib.html#masterIpcSend">masterIpcSend</a></i>(&nbsp;)</b>  -  send a message to a subagent<br><b><i><a href="./masterIoLib.html#masterIpcRcv">masterIpcRcv</a></i>(&nbsp;)</b>  -  wait for a reply from the subagent<br><b><i><a href="./masterIoLib.html#masterIpcAyt">masterIpcAyt</a></i>(&nbsp;)</b>  -  check the status of the IPC link<br><b><i><a href="./masterIoLib.html#masterIpcFree">masterIpcFree</a></i>(&nbsp;)</b>  -  free the IPC resources allocated by the SNMP master agent<br><b><i><a href="./masterIoLib.html#masterQueCleanup">masterQueCleanup</a></i>(&nbsp;)</b>  -  free resources allocated for SNMP master agent<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p>This module implements the I/O routines used by the SNMP master agent.  Asshipped, the WindNet SNMP code uses message queues to communicate betweenthe master agent and its subagents.  The SNMP master agent also uses a messagequeue to handle communication between its two component tasks, <b>tSnmpd</b>and <b>tMonQue</b>.  The <b>tSnmpd</b> task handles communication with the SNMP manager.The <b>tMonQue</b> task is a secondary task spawned from <b>tSnmpd</b> to receive messages from subagents.<p>When <b>tSnmpd</b> spawns <b>tMonQue</b>, it assigns <b><i>snmpQueMonitor</i>(&nbsp;)</b> to manage theprocess.  This function waits on the message queue that subagents use tosend messages to the master agent.  The <b><i>snmpQueMonitor</i>(&nbsp;)</b> function interpretsmessages on its queue using an <b>SA_MESSAGE_T</b> structure, which is defined in<b>ipcLib.h</b> as:<pre>typedef struct SA_MESSAGE_S    {    int            msgType;    MSG_Q_ID       saId;    EBUFFER_T      mesg;    } SA_MESSAGE_T;</pre>A switch internal to <b><i>snmpQueMonitor</i>(&nbsp;)</b> handles the message according tothe value of the <b>msgType</b> member.<p>If the message type is <b>CALL_QUERY_HANDLER</b>, the message is a response toa query from the master agent.  The buffer referenced in the <b>mesg</b> isthen transferred to the local message queue monitored by <b>tSnmpd</b>, whichis waiting for a query response from a subagent.<p>If the message type is <b>CALL_REG_HANDLER</b>, the message is either a registrationrequest, a deregistration request, or some other control message (such as a trap).  To respond to such requests, <b><i>snmpQueMonitor</i>(&nbsp;)</b> passes the buffer in <b>mesg</b> to <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b>.<p>If the message submitted to <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> is a registration request,it includes information on a set of leaves representing the objects thatthe subagent wants to add to the master agent's MIB tree.  If the messagepasses all checks, the objects are added to the master agent's MIB tree and<b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> returns success.  All objects registered in one messagebecome part of a group.  They share the same IPC information, and, if the IPClink to their subagent is broken, they are deactivated as a group.<p>If <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> returns a function value indicating success, italso returns a message for the subagent containing the group ID for thevariables just added.  The <b><i>snmpQueMonitor</i>(&nbsp;)</b> takes responsibility forforwarding this message to the subagent.  The subagent uses the group IDcontained in this message when it comes time to deregister, as well aswhen it must register instances of an already registered object.<p>The returned function value of <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> could indicate failureor an opcode. You might want to rewrite this code to do something different.For example, if the subagent had sent a trap up to the master agent, the returned value of <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> would be <b>SA_TRAP_REQUEST</b>, and the <i>vblist</i> parameter would contain a varbind list from the subagent.  In thiscase, you would want to modify <b><i>snmpQueMonitor</i>(&nbsp;)</b> to pass the trap on tothe SNMP manager.<p></blockquote><h4>MIB VARIABLES ADDED BY A SUBAGENT</h4><blockquote><p><p>These MIB variables that the subagent adds to the master agent's MIB treelook transparent to the SNMP manager that is in communication withthe master agent.  However, the method routines associated with these MIBvariables in the master agent are not standard MIB routines.  Instead, theyare special routines that know how to queue test, get, and set work on thesubagent that registered the MIB variables with the master agent.  From thepoint of view of the PDU processing code, these special method routineslook like any other method routines.  However, when <b>tSnmpd</b> executes oneof these routines, the special method routine actually passes the work onto a subagent while <b>tSnmpd</b> waits on a local message queue.<p>Because the subagent does not know about this local message queue, itsresponse to the master agent is somewhat indirect.  The only master agentmessage queue known to the subagent is the message queue managed by <b>tMonQue</b>,so the subagent puts its response on that queue.  When the <b><i>snmpQueMonitor</i>(&nbsp;)</b>function that <b>tMonQue</b> runs to monitor the message queue sees that themessage is a query response, it then transfers the message to the local queueupon which <b>tSnmpd</b> is awaiting a response.  When <b>tSnmpd</b> sees the response,it parses it and merges the message into the PDU processing system.<p></blockquote><h4>SERIAL VERSUS ASYNCHRONOUS SUBAGENT PROCESSING</h4><blockquote><p><p>In the shipped implementation, communication between the master agentand its subagents is handled serially.  For example, if the SNMPmanager made a request concerning three MIB variables managed by threedifferent subagents, the master agent would query each subagent in turn.After gathering all three responses, the master agent would then pack them up and ship the information back to the SNMP manager.<p>With some modifications to the code, you could rewrite the SNMP masteragent to query all three subagents simultaneously (see the description ofthe <b><i><a href="./subagentLib.html#snmpMasterHandlerAsync">snmpMasterHandlerAsync</a></i>(&nbsp;)</b> function defined in <b>subagentLib.c</b>).  That is,the master agent would query all three subagents one after the other withoutwaiting for a response after making each request.  If the subagents resideon different targets (each with its own processor), this asynchronous querymethod of multiple subagents lets you take advantage of the capacity forparallel processing.<p>However, if the subagents reside on different targets, you will also needto replace the code that implements the IPC mechanism used between themaster agent and its subagents.  In the shipped code, message queues serveas the IPC mechanism.  To support agents that reside on different machines,you must replace this IPC mechanism with something such as sockets.  Tomake this possible, the functions that implement the IPC mechanism areisolated to <b>masterIoLib.c</b> and <b>saIoLib.c</b>.  These files ship as source codethat you should feel free to edit as needed.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./masterIoLib.html#top">masterIoLib</a></b><hr><a name="masterIoInit"></a><p align=right><a href="rtnIndex.html"><i>Libraries :  Routines</i></a></p></blockquote><h1><i>masterIoInit</i>(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong><i>masterIoInit</i>(&nbsp;)</strong> - create the IPC mechanism at the SNMP master agent</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS masterIoInit ( void )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine, called from <b><i><a href="./snmpIoLib.html#snmpIoInit">snmpIoInit</a></i>(&nbsp;)</b>, creates the SNMP master agentside of the inter-process communication (IPC) mechanism used to carrymessages between subagents and the master agent.  In this implementation,<b><i><a href="./masterIoLib.html#masterIoInit">masterIoInit</a></i>(&nbsp;)</b> creates a single message queue.  The identity of thismessage queue is hard coded into every subagent.  The subagent puts amessage on this queue when it needs to send a message to the masteragent.<p>The message queue created by <b><i><a href="./masterIoLib.html#masterIoInit">masterIoInit</a></i>(&nbsp;)</b> is monitored by <b>tMonQue</b>.The <b>tMonQue</b> task is one of the two tasks used to implement the SNMPmaster agent.  The purpose of <b>tMonQue</b> is to note which messages inits queue are registration requests and which are responses to queries.If the message is a subagent registration request, <b>tMonQue</b> handles therequest and sends a message back to the subagent telling it whether theregistration was successful or not.<p>If the message is a response to a query, <b>tMonQue</b> transfers the messageto the message queue monitored by <b>tSnmpd</b>.  The <b>tSnmpd</b> task thenencodes the response in an SNMP packet and transmits the packet over asocket to the SNMP manager.<p>Although the shipped version of this function uses message queues as theIPC between the master agent and its subagents, the IPC mechanism isisolated to the relatively small number functions defined in masterIoLib.Thus, if necessary, you should have little trouble porting the code touse an IPC more suitable to your transport needs.<p>For example, you could use sockets instead of message queues.  However,if you decide to change the IPC mechanism, you must do so both in themaster agent and in its subagents.  This means that you must also modifythe functions defined in <b><a href="./saIoLib.html#top">saIoLib</a></b>, the library that defines the agent sideof the IPC mechanism.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK or ERROR.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./masterIoLib.html#top">masterIoLib</a></b><hr><a name="snmpMonitorSpawn"></a><p align=right><a href="rtnIndex.html"><i>Libraries :  Routines</i></a></p></blockquote><h1><i>snmpMonitorSpawn</i>(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong><i>snmpMonitorSpawn</i>(&nbsp;)</strong> - spawn <b>tMonQue</b> to run <b><i>snmpQueMonitor</i>(&nbsp;)</b></p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>void snmpMonitorSpawn (void)</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This function spawns the <b>tMonQue</b> task to run <b><i>snmpQueMonitor</i>(&nbsp;)</b> a functionthat waits on the message queue that subagents use to leave messages forthe master agent.  The <b><i>snmpQueMonitor</i>(&nbsp;)</b> waits forever on the master agent'smessage queue. When message comes in, it is interpreted using an <b>SA_MESSAGE_T</b>structure, which is defined in <b>ipcLib.h</b> as:<p><pre>typedef struct SA_MESSAGE_S   {   int            msgType;   MSG_Q_ID       saId;   EBUFFER_T      mesg;   } SA_MESSAGE_T;</pre>A switch internal to <b><i>snmpQueMonitor</i>(&nbsp;)</b> handles the message according tothe value of the <b>msgType</b> member.<p>If the message type is <b>CALL_QUERY_HANDLER</b>, the message is a response toa query from the master agent.  The buffer referenced in the <b>mesg</b> isthen transferred to the local message queue monitored by <b>tSnmpd</b>, wherea <b><i><a href="./masterIoLib.html#masterIpcRcv">masterIpcRcv</a></i>(&nbsp;)</b> routine is waiting for a query response from a subagent.<p>If the message type is <b>CALL_REG_HANDLER</b>, the message is a control messagesuch as a registration request, a deregistration request, or a trap.  Torespond to such requests, <b><i>snmpQueMonitor</i>(&nbsp;)</b> passes the buffer in <b>mesg</b>on to <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b>.<p>If the message in the buffer passed to <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> is notcorrectly formed, the returned function value indicates failure and<b><i>snmpQueMonitor</i>(&nbsp;)</b> drops the packet.<p>If the buffer passed to <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> is a correctly formedregistration request, <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> adds the specified objectsto the master agent's MIB tree.  If the buffer contains a correctlyformed deregistration request, <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> removes thespecified objects from the master agent's MIB tree.  In both casesthe returned value of <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> indicates success and its<i>rbuf</i> parameter contains a message that <b><i>snmpQueMonitor</i>(&nbsp;)</b> forwards tothe subagent that sent the message.<p>In the case of a successful registration request, the message sent tothe subagent contains a group ID for the objects just added to themaster agent's MIB tree.  When the subagent deregisters itself, itincludes this ID in its deregistration message to the master agent.It also uses this group ID when it must register instances of theobject just registered.<p>If the buffer passed to <b><i><a href="./subagentLib.html#snmpMasterHandlerWR">snmpMasterHandlerWR</a></i>(&nbsp;)</b> contains a trap, thereturned function value is <b>SA_TRAP_REQUEST</b>, the value extracted fromthe <b>opcode2</b> member of the header associated with the message.  Themessage itself (minus the header) is a varbind list.  It is returnedusing the <i>vbl</i> parameter.  The current implementation of <b><i>snmpQueMonitor</i>(&nbsp;)</b>just drops this message.  However, you can rewrite <b><i>snmpQueMonitor</i>(&nbsp;)</b>to make a <b><i><a href="./snmpIoLib.html#snmpIoTrapSend">snmpIoTrapSend</a></i>(&nbsp;)</b> that forwards the varbind list to the SNMPmanager.  Likewise, you can implement appropriate responses toother <b>opcode2</b> values.  Currently, <b>subagent.h</b> defines symbolic constantsfor opcodes 1 through 12 (with opcode 11, <b>SA_TRAP_REQUEST</b>, reservedfor trap requests).  If necessary you are free to use the remainingopcodes for message types specific to your implementation.<p>If your transport needs require that you rewrite <b><a href="./masterIoLib.html#top">masterIoLib</a></b> to usean IPC other than message queues, you might need to modify this function,which is called from <b><i><a href="./snmpIoLib.html#snmpIoMain">snmpIoMain</a></i>(&nbsp;)</b> just before a call to <b><i>snmpIoBody</i>(&nbsp;)</b>.For example, if you use sockets as your IPC between the SNMP master agentand its subagents, <b>tSnmpd</b> could monitor the socket connection with theSNMP manager as well as the socket connections with the SNMP subagents.<p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?