Esempio n. 1
0
 @Override
 public void addUser(Snmp snmp) {
   USM usm =
       new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
   SecurityModels.getInstance().addSecurityModel(usm);
   if (engineId != null) snmp.setLocalEngine(engineId.getValue(), 0, 0);
   snmp.getUSM()
       .addUser(
           securityName,
           new UsmUser(securityName, authProtocol, authPassphrase, privProtocol, privPassphrase));
 }
  /**
   * Start the Snmp session. If you forget the listen() method you will not get any answers because
   * the communication is asynchronous and the listen() method listens for answers.
   *
   * @throws IOException
   */
  @SuppressWarnings({"rawtypes", "unchecked"})
  private void start() throws IOException {
    TransportMapping transport = new DefaultUdpTransportMapping();
    snmp = new Snmp(transport);
    USM usm =
        new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(usm);
    transport.listen();

    System.out.println(transport.getListenAddress());
    System.out.println(transport.isListening());
  }
Esempio n. 3
0
  @Before
  public void setUp() throws Exception {
    // Create a global USM that all client calls will use
    MPv3.setEnterpriseID(5813);
    m_usm =
        new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(m_usm);

    m_agent =
        MockSnmpAgent.createAgentAndRun(
            classPathResource("penrose-lldp-mib.properties"), "127.0.0.1/1691");

    m_requestedVarbinds = new ArrayList<AnticipatedRequest>();
  }
Esempio n. 4
0
  private PDU sendRequestV3(PDU pdu) throws IOException {
    PDU response;

    OctetString userId = new OctetString("opennmsUser");
    OctetString pw = new OctetString("0p3nNMSv3");

    UserTarget target = new UserTarget();
    target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
    target.setSecurityName(userId);
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(SnmpConstants.version3);
    if (m_timeout > 0) {
      target.setTimeout(m_timeout);
    } else {
      target.setTimeout(5000);
    }

    TransportMapping<UdpAddress> transport = null;
    try {
      USM usm =
          new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
      SecurityModels.getInstance().addSecurityModel(usm);
      transport = new DefaultUdpTransportMapping();
      Snmp snmp = new Snmp(transport);

      UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
      snmp.getUSM().addUser(userId, user);

      transport.listen();

      ResponseEvent e = snmp.send(pdu, target);
      response = e.getResponse();
    } finally {
      if (transport != null) {
        transport.close();
      }
    }
    return response;
  }
Esempio n. 5
0
  @Before
  public void setUp() throws Exception {
    // Create a global USM that all client calls will use
    SNMP4JSettings.setEnterpriseID(5813);
    m_usm =
        new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(m_usm);

    try {
      m_agent =
          MockSnmpAgent.createAgentAndRun(
              classPathResource("penrose-lldp-mib.properties"),
              str(InetAddress.getLocalHost()) + "/0");
    } catch (Throwable e) {
      m_agent =
          MockSnmpAgent.createAgentAndRun(
              classPathResource("penrose-lldp-mib.properties"),
              str(InetAddressUtils.ONE_TWENTY_SEVEN) + "/0");
    }

    m_requestedVarbinds = new ArrayList<AnticipatedRequest>();
  }