<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2004</year><year>2020</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>Definition of Manager Net if</title>
    <prepared></prepared>
    <responsible></responsible>
    <docno></docno>
    <approved></approved>
    <checked></checked>
    <date></date>
    <rev></rev>
    <file>snmp_manager_netif.xml</file>
  </header>
  <p></p>
  <image file="snmp_manager_netif_1.gif">
    <icaption>The Purpose of Manager Net if</icaption>
  </image>

  <p>The Network Interface (Net If) process delivers SNMP PDUs to the
  manager server, and receives SNMP PDUs from the manager server. 
  The most common behaviour of a Net if process is that is receives 
  request PDU from the manager server, encodes the PDU into bytes
  and transmits the bytes onto the network to an agent. When the 
  reply from the agent is received by the Net if process, which it
  decodes into an SNMP PDU, which it sends to the manager server. </p>

  <p>However, that simple behaviour can be modified in numerous
  ways. For example, the Net if process can apply some kind of
  encrypting/decrypting scheme on the bytes. </p>

  <p>The snmp application provides two different modules, 
  <c>snmpm_net_if</c> (the default) and <c>snmpm_net_if_mt</c>, 
  both uses UDP as the transport protocol i.e the transport domains
  <c>transportDomainUdpIpv4</c> and/or <c>transportDomainUdpIpv6</c>.
  The difference between the two modules is that the latter is
  "multi-threaded", i.e. for each message/request a new process
  is created that processes the message/request and then exits. </p>

  <p>There is a <c>server</c> config option,
  <seeguide marker="snmp_config#manager_server_nis">netif_sup</seeguide>
  that enables "active" Net If supervision. This is very simple mechanism.
  The (supervising) process simply sends a
  <seeguide marker="#im_ping">ping</seeguide> message and expects a
  <seeguide marker="#om_pong">pong</seeguide> message response
  (withing a specific time).
  The interval between each <c>ping/pong</c> exhange is user configurable.
  As is the time that is allowed for the
  <seeguide marker="#om_pong">pong</seeguide>
  message to arrive.
  Both the NetIf module(s) provided with the app supports active supervision. 
  If a NetIf module/process is used which do not implement this, then
  the server cannot be configured with active supervision. </p>

  <p>It is also possible to write your own Net if process and
  this section describes how to do that.</p>

  <section>
    <marker id="mandatory_functions"></marker>
    <title>Mandatory Functions</title>
    <p>A Net If process must implement the SNMP manager 
    <seeerl marker="snmpm_network_interface">network interface behaviour</seeerl>. </p>
  </section>

  <section>
    <title>Messages</title>
    <p>The section <em>Messages</em> describes mandatory (with exception
    for the ping/pong messages) messages,
    which Net If must send to the manager server process. </p>
    <p>In this section a <c>Domain</c> field is the transport domain i.e
    one of <c>transportDomainUdpIpv4</c> or <c>transportDomainUdpIpv6</c>,
    and an <c>Addr</c> field is an
    <c>{</c><seetype marker="kernel:inet#ip_address"><c>IpAddr</c></seetype><c>,IpPort}</c> tuple.</p>

    <section>
      <marker id="outgoing_messages"></marker>
      <title>Outgoing Messages</title>

      <p>Net if must send the following message when it receives an
      SNMP PDU from the network that is aimed for the MasterAgent: </p>
      <pre>
Server ! {snmp_pdu, Pdu, Domain, Addr}
      </pre>
      <list type="bulleted">
	<item>
	  <p><c>Pdu</c> is an SNMP PDU record, as defined in
	  <c>snmp_types.hrl</c>, with the SNMP request.</p>
	</item>
	<item>
	  <p><c>Domain</c> is the source transport domain. </p>
	</item>
	<item>
	  <p><c>Addr</c> is the source address. </p>
	</item>
      </list>

      <pre>
Server ! {snmp_trap, Trap, Domain, Addr}
      </pre>
      <list type="bulleted">
	<item>
	  <p><c>Trap</c> is either an SNMP pdu record or an trappdu record, 
	  as defined in <c>snmp_types.hrl</c>, with the SNMP request.</p>
	</item>
	<item>
	  <p><c>Domain</c> is the source transport domain. </p>
	</item>
	<item>
	  <p><c>Addr</c> is the source address. </p>
	</item>
      </list>

      <pre>
Server ! {snmp_inform, Ref, Pdu, PduMS, Domain, Addr}
      </pre>
      <list type="bulleted">
	<item>
	  <p><c>Ref</c> is either the atom <c>ignore</c> or something
	  that can be used to identify the inform-request (e.g. request-id).
	  <c>ignore</c> is used if the response (acknowledgment) to the
	  inform-request has already been sent (this means that the server 
	  will not make the call to the 
	  <seeerl marker="snmpm_network_interface#inform_response">inform_response</seeerl> 
	  function). See the 
	  <seeguide marker="snmp_config#manager_irb">inform request behaviour</seeguide> 
	  configuration option for more info.</p>
	</item>
	<item>
	  <p><c>Pdu</c> is an SNMP PDU record, as defined in
	  <c>snmp_types.hrl</c>, with the SNMP request.</p>
	</item>
	<item>
	  <p><c>Domain</c> is the source transport domain. </p>
	</item>
	<item>
	  <p><c>Addr</c> is the source address. </p>
	</item>
      </list>

      <pre>
Server ! {snmp_report, Data, Domain, Addr}
      </pre>
      <list type="bulleted">
	<item>
	  <p><c>Data</c> is either <c>{ok, Pdu}</c> or 
	  <c>{error, ReqId, ReasonInfo, Pdu}</c>. Which one is used depends 
	  on the return value from the MPD 
	  <seeerl marker="snmpm_mpd#process_msg">process_msg</seeerl> function. If the MsgData is <c>ok</c>, 
	  the first is used, and if it is <c>{error, ReqId, Reason}</c>
	  the latter is used.</p>
	</item>
	<item>
	  <p><c>Pdu</c> is an SNMP PDU record, as defined in
	  <c>snmp_types.hrl</c>, with the SNMP request.</p>
	</item>
	<item>
	  <p><c>ReqId</c> is an integer.</p>
	</item>
	<item>
	  <p><c>ReasonInfo</c> is a term().</p>
	</item>
	<item>
	  <p><c>Domain</c> is the source transport domain. </p>
	</item>
	<item>
	  <p><c>Addr</c> is the source address. </p>
	</item>
      </list>

      <marker id="om_pong"></marker>
      <pre>
Supervisor ! {pong, self()}
      </pre>
      <list type="bulleted">
	<item>
	  <p><c>Supervisor</c> is the process that sent the
	  <seeguide marker="#im_ping">ping</seeguide> message (see below). </p>
	</item>
      </list>
    </section>

    <section>
      <marker id="incoming_messages"></marker>
      <title>Incoming Messages</title>
      <p>This section describes the incoming messages which a Net If
      process may choose to respond to. </p>

      <list type="bulleted">
        <item>
	  <marker id="im_ping"></marker>
	  <p><c>{ping, Supervisor}</c></p>
	  <p>This message is sent to the Net If process by a process that
	  has been configured to perfor "active supervision" of the Net If
	  process. The Net If process should respond immediately with
	  a <seeguide marker="#om_pong">pong</seeguide> message. </p>
          <list type="bulleted">
            <item>
	      <p><c>Supervisor</c> is a <c>pid()</c>. </p>
	    </item>
	  </list>
	</item>
      </list>
    </section>
  </section>

  <section>
    <title>Notes</title>
    <p>Since the Net if process is responsible for encoding and
    decoding of SNMP messages, it must also update the relevant
    counters in the SNMP group in MIB-II.  It can use the functions
    in the module <c>snmpm_mpd</c> for this purpose (refer to the 
    Reference Manual, section <c>snmp</c>, module <c>snmpm_mpd</c>
    for more details). </p>

    <p>There are also some useful functions for encoding and
    decoding of SNMP messages in the module <c>snmp_pdus</c>. </p>
  </section>
</chapter>

