4. Dispatcher 过程元素
4.1. 向网络发送 SNMP 消息
本节描述当应用希望向另一个 SNMP 实体发送 SNMP PDU 时 Dispatcher 遵循的过程.
4.1.1. 发送请求或通知
当应用希望向网络发送 SNMP Request 或 Notification 时, 遵循以下过程.
过程:
- 应用通过抽象 sendPdu 服务接口原语调用 Dispatcher, 请求 Dispatcher 发送 SNMP PDU:
statusInformation = sendPdu(
IN transportDomain, -- transport domain to be used
IN transportAddress, -- destination network address
IN messageProcessingModel, -- typically, SNMP version
IN securityModel, -- Security Model to use
IN securityName, -- on behalf of this principal
IN securityLevel, -- Level of Security requested
IN contextEngineID, -- data from/at this SNMP entity
IN contextName, -- data from/in this context
IN pduVersion, -- the version of the PDU
IN PDU, -- SNMP Protocol Data Unit
IN expectResponse, -- TRUE or FALSE
IN sendPduHandle -- the handle for matching incoming replies
)
-
如果 messageProcessingModel 值不表示 Dispatcher 已知的 Message Processing Model, 则向调用应用返回 errorIndication (unsupportedMsgProcessingModel). 该消息处理停止.
-
Dispatcher 请求适当的 Message Processing Model 根据其消息格式规范准备消息:
statusInformation = prepareOutgoingMessage(
IN transportDomain, -- as specified by application
IN transportAddress, -- as specified by application
IN messageProcessingModel, -- as specified by application
IN securityModel, -- as specified by application
IN securityName, -- as specified by application
IN securityLevel, -- as specified by application
IN contextEngineID, -- as specified by application
IN contextName, -- as specified by application
IN pduVersion, -- as specified by application
IN PDU, -- as specified by application
IN expectResponse, -- as specified by application
IN sendPduHandle, -- as determined by application
OUT destTransportDomain, -- destination transport domain
OUT destTransportAddress, -- destination transport address
OUT outgoingMessage, -- the message to send
OUT outgoingMessageLength -- its length
)
-
如果 statusInformation 参数中的 statusInformation 不是 success, Dispatcher 将 statusInformation 返回给调用应用. 该消息处理停止.
-
如果 statusInformation 为 success, Dispatcher 通过 transportDomain 和 transportAddress 指定的传输向网络发送准备好的消息.
-
Dispatcher 向调用应用返回 success.
4.1.2. 向网络发送响应
当应用希望向网络发送响应时, 遵循以下过程.
过程:
- 应用使用 returnResponsePdu 抽象服务接口调用 Dispatcher, 请求 Dispatcher 发送 SNMP PDU:
result = returnResponsePdu(
IN messageProcessingModel, -- typically, SNMP version
IN securityModel, -- Security Model in use
IN securityName, -- on behalf of this principal
IN securityLevel, -- same as on incoming request
IN contextEngineID, -- data from/at this SNMP entity
IN contextName, -- data from/in this context
IN pduVersion, -- the version of the PDU
IN PDU, -- SNMP Protocol Data Unit
IN maxSizeResponseScopedPDU, -- maximum size of the Response PDU
IN stateReference, -- reference to state information
IN statusInformation -- success or errorIndication
)
注意: 抽象数据元素 securityModel, securityName, securityLevel, contextEngineID, contextName 和 stateReference 应与最初接收请求并传递给应用时确定的值相同. 可以使用 stateReference 作为键从缓存中取回这些值.
-
如果 messageProcessingModel 值不表示 Dispatcher 已知的 Message Processing Model, 则向调用应用返回 errorIndication (unsupportedMsgProcessingModel). 该消息处理停止.
-
Dispatcher 请求适当的 Message Processing Model 根据其消息格式规范准备响应消息:
result = prepareResponseMessage(
IN messageProcessingModel, -- as provided by application
IN securityModel, -- as provided by application
IN securityName, -- as provided by application
IN securityLevel, -- as provided by application
IN contextEngineID, -- as provided by application
IN contextName, -- as provided by application
IN pduVersion, -- as provided by application
IN PDU, -- as provided by application
IN maxSizeResponseScopedPDU, -- as provided by application
IN stateReference, -- as provided by application
IN statusInformation, -- as provided by application
OUT destTransportDomain, -- destination transport domain
OUT destTransportAddress, -- destination transport address
OUT outgoingMessage, -- the message to send
OUT outgoingMessageLength -- its length
)
-
如果 result 参数中的 result 不是 success, Dispatcher 将 errorIndication 返回给调用应用. 该消息处理停止.
-
如果 result 为 success, Dispatcher 通过 destTransportDomain 和 destTransportAddress 指定的传输向网络发送准备好的消息.
-
Dispatcher 向调用应用返回 success.
4.2. 从网络接收 SNMP 消息
本节描述 Dispatcher 从网络接收 SNMP 消息时遵循的过程.
4.2.1. 收到 SNMP 消息的消息分派
Dispatcher 从网络接收 SNMP Message 时, 遵循以下过程:
-
Dispatcher 从网络接收消息.
-
Dispatcher 确定 SNMP 消息版本. 如果数据包无法充分解析以确定版本, 则递增 snmpInASNParseErrs 计数器 [RFC3418], 并丢弃该消息且不再进一步处理. 该消息处理停止.
-
Dispatcher 根据 SNMP 消息版本确定适当的 Message Processing Model.
-
如果 Dispatcher 不知道该 SNMP Message 版本, 则递增 snmpInBadVersions 计数器 [RFC3418], 并丢弃该消息且不再进一步处理. 该消息处理停止.
4.2.2. 传入消息的 PDU 分派
消息分派确定 Message Processing Model 后, 使用以下抽象服务接口请求 Message Processing Model 从消息中提取 PDU 和数据:
result = prepareDataElements(
IN transportDomain, -- origin transport domain
IN transportAddress, -- origin transport address
IN wholeMsg, -- as received from the network
IN wholeMsgLength, -- as received from the network
OUT messageProcessingModel, -- typically, SNMP version
OUT securityModel, -- Security Model in use
OUT securityName, -- on behalf of this principal
OUT securityLevel, -- Level of Security requested
OUT contextEngineID, -- data from/at this SNMP entity
OUT contextName, -- data from/in this context
OUT pduVersion, -- the version of the PDU
OUT PDU, -- SNMP Protocol Data Unit
OUT pduType, -- SNMP PDU type
OUT sendPduHandle, -- handle for matched request
OUT maxSizeResponseScopedPDU, -- maximum size of Response PDU
OUT statusInformation, -- success or errorIndication
OUT stateReference -- reference to state information
)
如果 result errorIndication 被设置为 noError 以外的值, 则丢弃该消息且不再进一步处理. 该消息处理停止.
4.2.2.1. 传入请求和通知
当 pduType 的值指示消息包含 Request 或 Notification 时, 遵循以下过程分派 PDU:
-
根据 pduType, contextEngineID 和 contextName, 选择适当的应用.
a. 如果没有应用为 pduType, contextEngineID 和 contextName 的组合注册, 且没有应用为 pduType 与 contextEngineID 且 contextName 为空的组合注册, 则:
- 如果 pduType 是 confirmed, 则向消息发起者发送 Report PDU. Dispatcher 调用适当的 Message Processing Model, 使用 reportPDU 抽象服务接口原语生成错误报告:
result = reportPDU(
IN messageProcessingModel, -- typically, SNMP version
IN securityModel, -- Security Model in use
IN securityName, -- on behalf of this principal
IN securityLevel, -- same as on incoming request
IN contextEngineID, -- data from/at this SNMP entity
IN contextName, -- data from/in this context
IN pduVersion, -- the version of the PDU
IN PDU, -- SNMP Protocol Data Unit
IN maxSizeResponseScopedPDU, -- maximum size of the Response PDU
IN stateReference, -- reference to state information
IN statusInformation -- error indication
)
- 丢弃该消息. 该消息处理停止.
b. 如果 pduType 是 unconfirmed, 则丢弃该消息. 该消息处理停止.
- 使用 processPdu 抽象服务接口将 PDU 分派给应用:
processPdu(
IN messageProcessingModel, -- typically, SNMP version
IN securityModel, -- Security Model in use
IN securityName, -- on behalf of this principal
IN securityLevel, -- Level of Security
IN contextEngineID, -- data from/at this SNMP entity
IN contextName, -- data from/in this context
IN pduVersion, -- the version of the PDU
IN PDU, -- SNMP Protocol Data Unit
IN maxSizeResponseScopedPDU, -- maximum size of Response PDU
IN stateReference -- reference to state information
)
4.2.2.2. 传入响应
当 pduType 指示 Response, Report 或其他 Class 2 类型 PDU 时, 遵循以下过程分派 PDU:
-
sendPduHandle 中的值用于确定应将 PDU 分派给哪个应用.
-
如果未找到应用注册, 则递增 snmpUnknownPDUHandlers 计数器 [RFC3418], 并丢弃该消息. 该消息处理停止.
-
否则, 使用 processResponsePdu 抽象服务接口将消息分派给应用:
processResponsePdu(
IN messageProcessingModel, -- typically, SNMP version
IN securityModel, -- Security Model in use
IN securityName, -- on behalf of this principal
IN securityLevel, -- Level of Security
IN contextEngineID, -- data from/at this SNMP entity
IN contextName, -- data from/in this context
IN pduVersion, -- the version of the PDU
IN PDU, -- SNMP Protocol Data Unit
IN statusInformation, -- success or errorIndication
IN sendPduHandle -- handle for matched request
)
4.3. 处理 PDU 类型的应用注册
希望处理某些 PDU 的应用必须向 PDU Dispatcher 注册. 应用指定它希望负责的 pduType, contextEngineID 和 contextName 组合.
应用注册遵循以下过程:
- 应用使用 registerContextEngineID 抽象服务接口原语调用 PDU Dispatcher:
statusInformation = registerContextEngineID(
IN contextEngineID, -- take responsibility for this one
IN pduType -- the pduType(s) to be registered
)
-
如果另一个应用已经为指定的 contextEngineID 和 pduType 注册, 则向调用应用返回 errorIndication (duplicateRegistration). 注册处理停止.
-
否则, PDU Dispatcher 保存该注册并返回 success.
4.4. 处理 PDU 类型的应用注销
不再希望处理某些类型 PDU 的应用必须向 PDU Dispatcher 注销. 应用必须指定它不再希望负责的 contextEngineID 和 pduType 组合.
应用注销遵循以下过程:
- 应用使用 unregisterContextEngineID 抽象服务接口原语调用 PDU Dispatcher:
unregisterContextEngineID(
IN contextEngineID, -- give up responsibility for this
IN pduType -- the pduType(s) to be unregistered
)
-
如果找到应用注册, 则删除该注册.
-
如果未找到此类注册, 则忽略该请求.