Пример #1
0
    def test_direct_meter_entry_invalid(self):
        ce = sh.DirectMeterEntry("ExactOne_meter")
        with self.assertRaisesRegex(UserError, "table_entry must be an instance of TableEntry"):
            ce.table_entry = 0xbad
        with self.assertRaisesRegex(UserError, "This DirectMeterEntry is for table"):
            ce.table_entry = sh.TableEntry("TernaryOne")
        with self.assertRaisesRegex(UserError, "Direct meters are not index-based"):
            ce.index = 1

        te = sh.TableEntry("LpmOne")(action="actionA")
        with self.assertRaisesRegex(UserError, "Table has no direct meter"):
            te.meter_config.cir = 100
Пример #2
0
    def test_direct_meter_entry(self):
        ce = sh.DirectMeterEntry("ExactOne_meter")
        ce.table_entry.match["header_test.field32"] = "10.0.0.0"
        ce.cir = 1
        ce.cburst = 2
        ce.pir = 3
        ce.pburst = 4
        expected_entry = """
table_entry {
  table_id: 33582705
  match {
    field_id: 1
    exact {
      value: "\\x0a\\x00\\x00\\x00"
    }
  }
}
config {
  cir: 1
  cburst: 2
  pir: 3
  pburst: 4
}
"""
        expected_req = self.make_write_request(
            p4runtime_pb2.Update.MODIFY, P4RuntimeEntity.direct_meter_entry,
            expected_entry)
        ce.modify()
        self.servicer.Write.assert_called_with(ProtoCmp(expected_req), ANY)

        self.simple_read_check(expected_req.updates[0].entity, ce,
                               P4RuntimeEntity.direct_meter_entry)

        ce.table_entry = None
        expected_entry = """
table_entry {
  table_id: 33582705
}
config {
  cir: 1
  cburst: 2
  pir: 3
  pburst: 4
}
"""
        expected_req = self.make_write_request(
            p4runtime_pb2.Update.MODIFY, P4RuntimeEntity.direct_meter_entry,
            expected_entry)
        ce.modify()
        self.servicer.Write.assert_called_with(ProtoCmp(expected_req), ANY)