def portBasedIngressRateMonitoring(dev): #dev = Device() ''' This method was written for port based rate monitoring for ingresws. which we are not using at this momnent :param dev: :return: ''' for portIndex in dev.portToQueueRateMap: portQueueRate = dev.portToQueueRateMap.get(portIndex) cir = portQueueRate * ConfConst.INGRESS_STATS_METER_CIR_THRESHOLD_FACTOR cburst = portQueueRate * ConfConst.INGRESS_STATS_METER_CBURST_FACTOR pir = portQueueRate * ConfConst.INGRESS_STATS_METER_PIR_FACTOR pburst = portQueueRate * ConfConst.INGRESS_STATS_METER_PBURST_FACTOR dev.addExactMatchEntryWithoutActionParam( tableName= "IngressPipeImpl.ingress_rate_monitor_control_block.ingress_stats", fieldName="standard_metadata.ingress_port", fieldValue=portIndex, actionName= "IngressPipeImpl.ingress_rate_monitor_control_block.monitor_incoming_flow" ) ce = sh.DirectMeterEntry( dev, "IngressPipeImpl.ingress_rate_monitor_control_block.ingress_meter") ce.table_entry.match["standard_metadata.ingress_port"] = portIndex ce.cir = int(cir) ce.cburst = int(cburst) ce.pir = int(pir) ce.pburst = int(pburst) ce.modify() logging.info("Modified meter entry in device: " + str(dev))
def portBasedEgressRateMonitoring(dev): for portIndex in dev.portToQueueRateMap: dev.addExactMatchEntryWithoutActionParam( tableName= "EgressPipeImpl.egress_rate_monitor_control_block.egress_rate_monitor_table", fieldName="standard_metadata.egress_port", fieldValue=portIndex, actionName= "EgressPipeImpl.egress_rate_monitor_control_block.monitor_outgoing_flow" ) portQueueRate = dev.portToQueueRateMap.get(portIndex) cir = portQueueRate * ConfConst.EGRESS_STATS_METER_CIR_THRESHOLD_FACTOR cburst = portQueueRate * ConfConst.EGRESS_STATS_METER_CBURST_FACTOR pir = portQueueRate * ConfConst.EGRESS_STATS_METER_PIR_FACTOR pburst = portQueueRate * ConfConst.EGRESS_STATS_METER_PBURST_FACTOR ce = sh.DirectMeterEntry( dev, "EgressPipeImpl.egress_rate_monitor_control_block.egress_meter") ce.table_entry.match["standard_metadata.egress_port"] = portIndex ce.cir = int(cir) ce.cburst = int(cburst) ce.pir = int(pir) ce.pburst = int(pburst) ce.modify() logging.info("Modified meter entry in device: " + str(dev))
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)
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
def addDownstreamRoutingRuleForLeafSwitch(dev): for hPort in dev.portToHostMap.keys(): host = (dev.portToHostMap.get(hPort)) actionParamNameList = ["port_num", "dmac"] actionParamValueList = [hPort, host.fabric_host_config.mac] dev.addExactMatchEntryWithMultipleActionParameter(tableName="IngressPipeImpl.downstream_routing_control_clock.downstream_routing_table", fieldName="hdr.ipv6.dst_addr", fieldValue=host.basic.ips[0], actionName="IngressPipeImpl.downstream_routing_control_clock.set_downstream_egress_port", actionParamNameList=actionParamNameList, actionParamValueList=actionParamValueList) ce = sh.DirectMeterEntry(dev, "host_egress_meter") ce.table_entry.match["hdr.ipv6.dst_addr"] = host.basic.ips[0] ce.cir = 500 * 1024 ce.cburst = 25 * 1024 ce.pir = 600 * 1024 ce.pburst = 25 * 1024 ce.modify()