def test_getOIDsInRange(self):
     c = AX.MIBControl()
     c.addNode((0, 1))
     c.addNode((0, 2, 0), 10, 11)
     c.addNode((0, 2, 1), 20, 21)
     c.addNode((0, 2, 2), 30, 31)
     c.addNode((0, 2, 3), 40, 41)
     c.addNode((0, 4, 1, 0), 50, 51)
     # Test range too early
     rng = AP.SearchRange((0, 0, 0), (0, 0, 5))
     self.assertEqual(c.getOIDsInRange(rng), [])
     # Test range too late
     rng = AP.SearchRange((6, 0, 0), (6, 0, 5))
     self.assertEqual(c.getOIDsInRange(rng), [])
     # Test nothing implemented in range
     rng = AP.SearchRange((0,), (0, 1, 5))
     self.assertEqual(c.getOIDsInRange(rng), [])
     # Test in range
     rng = AP.SearchRange((0, 2, 0), (0, 2, 3))
     self.assertEqual(c.getOIDsInRange(rng),
                      [(AP.OID((0, 2, 1)), 20, 21),
                       (AP.OID((0, 2, 2)), 30, 31)])
     # Test unbounded range
     rng = AP.SearchRange((0, 2, 0), ())
     self.assertEqual(c.getOIDsInRange(rng),
                      [(AP.OID((0, 2, 1)), 20, 21),
                       (AP.OID((0, 2, 2)), 30, 31),
                       (AP.OID((0, 2, 3)), 40, 41),
                       (AP.OID((0, 4, 1, 0)), 50, 51)])
 def test_handleGetNextPDU(self):
     readReturns = [1]
     read = (lambda oid: AP.Varbind(AP.VALUE_INTEGER,
                                    oid, readReturns.pop(0)))
     mjig = AX.MIBControl()
     mjig.addNode((0, 0), read)
     mjig.addNode((0, 1), read)
     sock = jigs.SocketJig()
     p = AX.PacketControl(sock, mjig)
     p.sessionID = 42
     # Test successful
     pkt = AP.GetNextPDU(True, 42, 23, 100, [AP.SearchRange((0, 0), ())])
     p.handle_GetNextPDU(pkt)
     self.assertEqual(len(sock.data), 1)
     sentPkt = AP.decode_packet(sock.data[0])[0]
     respPkt = AP.ResponsePDU(True, 42, 23, 100, 0, 0, 0,
                              (AP.Varbind(AP.VALUE_INTEGER, (0, 1), 1),))
     self.assertEqual(sentPkt, respPkt)
     # Test non-existent
     sock.data = []
     pkt = AP.GetNextPDU(True, 42, 23, 100, [AP.SearchRange((1, 0), ())])
     p.handle_GetNextPDU(pkt)
     self.assertEqual(len(sock.data), 1)
     sentPkt = AP.decode_packet(sock.data[0])[0]
     respPkt = AP.ResponsePDU(True, 42, 23, 100, 0, 0, 0,
                              (AP.Varbind(AP.VALUE_END_OF_MIB_VIEW,
                                          (1, 0)),))
     self.assertEqual(sentPkt, respPkt)
Beispiel #3
0
 def test_handle_GetBulkPDU(self):
     readReturns = [1, 2, 3, 4, 5, 6]
     read = (
         lambda oid: AP.Varbind(AP.VALUE_INTEGER, oid, readReturns.pop(0)))
     mjig = AX.MIBControl()
     # non-repeated
     mjig.addNode((0, 0), read)
     mjig.addNode((0, 1), read)  # shouldn't see
     mjig.addNode((1, 0), read)
     mjig.addNode((1, 1), read)  # shouldn't see
     # repeated
     mjig.addNode((2, 0), read)
     mjig.addNode((2, 1), read)
     mjig.addNode((2, 2), read)  # shouldn't see
     mjig.addNode((3, 0), read)
     mjig.addNode((3, 1), read)
     mjig.addNode((3, 2), read)  # shouldn't see
     mjig.addNode((4, 0), read)  # shouldn't see
     sock = jigs.SocketJig()
     p = AX.PacketControl(sock, mjig)
     p.sessionID = 42
     pkt = AP.GetBulkPDU(True, 42, 23, 100, 2, 2, [
         AP.SearchRange((0, ), (1, ), True),
         AP.SearchRange((1, ), (2, ), True),
         AP.SearchRange((2, 0), (3, ), True),
         AP.SearchRange((3, 0), (), True)
     ])
     p.handle_GetBulkPDU(pkt)
     self.assertEqual(len(sock.data), 1)
     sentPkt = AP.decode_packet(sock.data[0])[0]
     respPkt = AP.ResponsePDU(
         True, 42, 23, 100, 0, 0, 0,
         (AP.Varbind(AP.VALUE_INTEGER,
                     (0, 0), 1), AP.Varbind(AP.VALUE_INTEGER, (1, 0), 2),
          AP.Varbind(AP.VALUE_INTEGER,
                     (2, 0), 3), AP.Varbind(AP.VALUE_INTEGER, (2, 1), 4),
          AP.Varbind(AP.VALUE_INTEGER,
                     (3, 0), 5), AP.Varbind(AP.VALUE_INTEGER, (3, 1), 6)))
     self.assertEqual(sentPkt, respPkt)