2013-07-18 32 views
4

我想通過snmp GETBULK獲取路由器的接口信息,但是當我使用它時,該記錄被返回。SNMP GETBULK問題:只能得到零件記錄(如59條記錄,但有100條以上記錄)

的代碼如下:

public static void main(String[] args) throws IOException, InterruptedException { 
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping()); 
    snmp.listen(); 

    CommunityTarget target = new CommunityTarget(); 
    target.setCommunity(new OctetString("public")); 
    target.setVersion(SnmpConstants.version2c); 
    target.setAddress(new UdpAddress("127.0.0.1/161")); 
    target.setTimeout(3000); //3s 
    target.setRetries(1); 

    PDU pdu = new PDU(); 
    pdu.setType(PDU.GETBULK); 
    pdu.setMaxRepetitions(200); 
    pdu.setNonRepeaters(0); 
    pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.31.1.1.1.1"))); 

    ResponseEvent responseEvent = snmp.send(pdu, target); 
    PDU response = responseEvent.getResponse(); 

    if (response == null) { 
     System.out.println("TimeOut..."); 
    } 
    else 
    { 
     if (response.getErrorStatus() == PDU.noError) 
     { 
      Vector<? extends VariableBinding> vbs = response.getVariableBindings(); 
      for (VariableBinding vb : vbs) { 
       System.out.println(vb + " ," + vb.getVariable().getSyntaxString()); 
      } 
     } 
     else 
     { 
      System.out.println("Error:" + response.getErrorStatusText()); 
     } 
    } 
} 

執行它後,有59條記錄被退回,但如果我使用GETNEXT,讓他們有被退回約197條記錄。

任何想法?

希望任何人都可以幫助我,在此先感謝。

回答

3

你的回答有多大?請記住 - getbulk響應必須適合單個UDP數據包。這是65,535字節的絕對限制 - 或者如果您的MTU限制可能小至1,500字節。

+0

在此先感謝!你是對的! – azury

+1

那麼解決方案是什麼?你如何獲得更多的數據? – darrickc

+1

@darrickc將您的請求分解爲幾個單獨的請求。或限制對您的積分請求的最大響應數量。 –

相關問題