def test_table_direct_with_group_id(self): te = sh.TableEntry("ExactOne") te.match["header_test.field32"] = "10.0.0.0" with self.assertRaisesRegex(UserError, "does not support groups"): te.group_id = 1 with self.assertRaisesRegex(UserError, "does not support groups"): te = sh.TableEntry("ExactOne")(group_id=1)
def test_table_indirect_with_direct_action(self): te = sh.TableEntry("IndirectWS") te.match["header_test.field32"] = "10.0.0.0" with self.assertRaisesRegex(UserError, "does not support direct actions"): te.action = sh.Action("actionA") with self.assertRaisesRegex(UserError, "does not support direct actions"): te = sh.TableEntry("IndirectWS")(action="actionA")
def modifyLPMMatchEntryWithGroupActionWith2RangeField( self, tableName, fieldName, fieldValue, prefixLength, rangeField1Name, rangeField1LowerValue, rangefield1HigherValue, rangeField2Name, rangeField2LowerValue, rangefield2HigherValue, # old fields are required to find table entries. rangeField2ModifedLowerValue, rangefield2ModifiedHigherValue, actionName, actionParamName, actionParamValue, groupID=None, priority=None): # self.p4runtimeLock.acquire(blocking=True) # o,e = self.executeCommand("table_dump "+ tableName+"\n") # logger.info(str(self.devName)+ "At start of modifyLPMMatchEntryWithGroupActionWith2RangeField"+str(o)) te = sh.TableEntry(self, tableName) te.match[fieldName] = "" + fieldValue + "/" + str(prefixLength) te.match[rangeField1Name] = str(rangeField1LowerValue) + ".." + str( rangefield1HigherValue) # "0/1024" te.match[rangeField2Name] = str(rangeField2LowerValue) + ".." + str( rangefield2HigherValue) # "0/1024" if ((actionParamName != None) and (actionParamValue != None)): te.action[actionParamName] = actionParamValue if priority != None: te.priority = priority if (groupID != None): te.group_id = groupID te.delete() te._update_msg() # o,e = self.executeCommand("table_dump "+ tableName+"\n") # logger.info(str(self.devName)+ "After dlting old entry "+str(o)) #logger.info("Deleted TE is "+te._info) te = sh.TableEntry(self, tableName) te.match[fieldName] = "" + fieldValue + "/" + str(prefixLength) te.match[rangeField1Name] = str(rangeField1LowerValue) + ".." + str( rangefield1HigherValue) # "0/1024" te.match[rangeField2Name] = str( rangeField2ModifedLowerValue) + ".." + str( rangefield2ModifiedHigherValue) # "0/1024" if ((actionParamName != None) and (actionParamValue != None)): te.action[actionParamName] = actionParamValue if priority != None: te.priority = priority if (groupID != None): te.group_id = groupID te.insert()
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 addExactMatchEntryWithMultipleFieldMultipleActionParam( self, tableName, fieldNameList, fieldValueList, actionName, actionParamNameList, actionParamValueList): if (len(fieldNameList) != len(fieldValueList)): logger.info( "Can not insert exact match entries. Because number of field and values are not equal" ) te = sh.TableEntry(self, tableName)(action=actionName) if len(fieldNameList) != len(fieldValueList): logger.info( "Number of match field and number of values for them are not matching. Severe Problem. Exiting!!" ) exit(1) if len(actionParamNameList) != len(actionParamValueList): logger.info( "Number of action parameters and number of values for them are not matching. Severe Problem. Exiting!!" ) exit(1) for i in range(0, len(fieldValueList)): te.match[fieldNameList[i]] = "" + str(fieldValueList[i]) for i in range(0, len(actionParamNameList)): te.match[actionParamNameList[i]] = "" + str( actionParamValueList[i]) te.insert()
def test_direct_counter_entry_2(self): te = sh.TableEntry("ExactOne")(action="actionA") te.match["header_test.field32"] = "10.0.0.0" te.action["param"] = "aa:bb:cc:dd:ee:ff" te.counter_data.packet_count = 100 expected_entry = """ table_id: 33582705 match { field_id: 1 exact { value: "\\x0a\\x00\\x00\\x00" } } action { action { action_id: 16783703 params { param_id: 1 value: "\\xaa\\xbb\\xcc\\xdd\\xee\\xff" } } } counter_data { packet_count: 100 } """ expected_req = self.make_write_request(p4runtime_pb2.Update.INSERT, P4RuntimeEntity.table_entry, expected_entry) te.insert() self.servicer.Write.assert_called_once_with(ProtoCmp(expected_req), ANY) self.simple_read_check(expected_req.updates[0].entity, te, P4RuntimeEntity.table_entry)
def test_table_entry_ternary(self, input_, value, mask): te = sh.TableEntry("TernaryOne")(action="actionA") te.match["header_test.field32"] = input_ te.action["param"] = "aa:bb:cc:dd:ee:ff" te.insert() expected_entry = """ table_id: 33584148 match { field_id: 1 ternary { value: "%s" mask: "%s" } } action { action { action_id: 16783703 params { param_id: 1 value: "\\xaa\\xbb\\xcc\\xdd\\xee\\xff" } } } """ % (value, mask) expected_req = self.make_write_request(p4runtime_pb2.Update.INSERT, P4RuntimeEntity.table_entry, expected_entry) self.servicer.Write.assert_called_once_with(ProtoCmp(expected_req), ANY)
def test_table_entry_lpm(self, input_, value, length): te = sh.TableEntry("LpmOne")(action="actionA") te.match["header_test.field32"] = input_ te.action["param"] = "aa:bb:cc:dd:ee:ff" te.insert() # Cannot use format here because it would require escaping all braces, # which would make wiriting tests much more annoying expected_entry = """ table_id: 33567650 match { field_id: 1 lpm { value: "%s" prefix_len: %s } } action { action { action_id: 16783703 params { param_id: 1 value: "\\xaa\\xbb\\xcc\\xdd\\xee\\xff" } } } """ % (value, length) expected_req = self.make_write_request(p4runtime_pb2.Update.INSERT, P4RuntimeEntity.table_entry, expected_entry) self.servicer.Write.assert_called_once_with(ProtoCmp(expected_req), ANY)
def addLPMMatchEntryWithGroupActionWith2RangeField(self, tableName, fieldName, fieldValue, prefixLength, rangeField1Name, rangeField1LowerValue, rangefield1HigherValue, rangeField2Name, rangeField2LowerValue, rangefield2HigherValue, actionName, actionParamName, actionParamValue, groupID=None, priority=None): te = sh.TableEntry(self, tableName) te.match[fieldName] = "" + fieldValue + "/" + str(prefixLength) te.match[rangeField1Name] = str(rangeField1LowerValue) + ".." + str( rangefield1HigherValue) # "0/1024" te.match[rangeField2Name] = str(rangeField2LowerValue) + ".." + str( rangefield2HigherValue) # "0/1024" if ((actionParamName != None) and (actionParamValue != None)): te.action[actionParamName] = actionParamValue if priority != None: te.priority = priority if (groupID != None): te.group_id = groupID te.insert()
def test_table_entry_exact(self): te = sh.TableEntry("ExactOne")(action="actionA") te.match["header_test.field32"] = "0x12345678" te.action["param"] = "aa:bb:cc:dd:ee:ff" te.insert() expected_entry = """ table_id: 33582705 match { field_id: 1 exact { value: "\\x12\\x34\\x56\\x78" } } action { action { action_id: 16783703 params { param_id: 1 value: "\\xaa\\xbb\\xcc\\xdd\\xee\\xff" } } } """ expected_req = self.make_write_request(p4runtime_pb2.Update.INSERT, P4RuntimeEntity.table_entry, expected_entry) self.servicer.Write.assert_called_once_with(ProtoCmp(expected_req), ANY)
def removeLPMMatchEntryWithGroupActionWithRangeField( self, tableName, fieldName, fieldValue, prefixLength, rangeFieldName, rangeFieldLowerValue, rangefieldHigherValue, actionName, actionParamName, actionParamValue, groupID=None, priority=None): te = sh.TableEntry(self, tableName) te.match[fieldName] = "" + fieldValue + "/" + str(prefixLength) te.match[rangeFieldName] = str(rangeFieldLowerValue) + ".." + str( rangefieldHigherValue) # "0..1024" if ((actionParamName != None) and (actionParamValue != None)): te.action[actionParamName] = actionParamValue if priority != None: te.priority = priority if (groupID != None): te.group_id = groupID te.delete()
def test_table_entry_range(self): te = sh.TableEntry("RangeOne")(action="actionA") te.match["header_test.field32"] = "0..1024" te.action["param"] = "aa:bb:cc:dd:ee:ff" te.insert() expected_entry = """ table_id: 33603558 match { field_id: 1 range { low: "\\x00\\x00\\x00\\x00" high: "\\x00\\x00\\x04\\x00" } } action { action { action_id: 16783703 params { param_id: 1 value: "\\xaa\\xbb\\xcc\\xdd\\xee\\xff" } } } """ expected_req = self.make_write_request(p4runtime_pb2.Update.INSERT, P4RuntimeEntity.table_entry, expected_entry) self.servicer.Write.assert_called_once_with(ProtoCmp(expected_req), ANY)
def test_direct_counter_entry_invalid(self): ce = sh.DirectCounterEntry("ExactOne_counter") with self.assertRaisesRegex( UserError, "table_entry must be an instance of TableEntry"): ce.table_entry = 0xbad with self.assertRaisesRegex(UserError, "This DirectCounterEntry is for table"): ce.table_entry = sh.TableEntry("TernaryOne") with self.assertRaisesRegex(UserError, "Direct counters are not index-based"): ce.index = 1 te = sh.TableEntry("LpmOne")(action="actionA") with self.assertRaisesRegex(UserError, "Table has no direct counter"): te.counter_data.packet_count = 100 te = sh.TableEntry("ExactOne")(action="actionA") with self.assertRaisesRegex( UserError, "Counter 'ExactOne_counter' is of type 'PACKETS"): te.counter_data.byte_count = 100
def test_table_indirect_oneshot(self): te = sh.TableEntry("IndirectWS") te.match["header_test.field32"] = "10.0.0.0" a1 = sh.Action("actionA") a1["param"] = "aa:bb:cc:dd:ee:ff" a2 = sh.Action("actionB") a2["param"] = "10" te.oneshot.add(a1).add(a2, weight=2) expected_entry = """ table_id: 33586946 match { field_id: 1 exact { value: "\\x0a\\x00\\x00\\x00" } } action { action_profile_action_set { action_profile_actions { action { action_id: 16783703 params { param_id: 1 value: "\\xaa\\xbb\\xcc\\xdd\\xee\\xff" } } weight: 1 } action_profile_actions { action { action_id: 16809468 params { param_id: 1 value: "\\x0a" } } weight: 2 } } } """ te.insert() expected_req = self.make_write_request(p4runtime_pb2.Update.INSERT, P4RuntimeEntity.table_entry, expected_entry) self.servicer.Write.assert_called_once_with(ProtoCmp(expected_req), ANY) self.simple_read_check(expected_req.updates[0].entity, te, P4RuntimeEntity.table_entry)
def addExactMatchEntryWithMultipleField(self, tableName, fieldNameList, fieldValueList, actionName, actionParamName, actionParamValue): if (len(fieldNameList) != len(fieldValueList)): logger.info( "Can not insert exact match entries. Because number of field and values are not equal" ) te = sh.TableEntry(self, tableName)(action=actionName) # te.match[fieldName] = "" + fieldValue te.action[actionParamName] = actionParamValue for i in range(0, len(fieldValueList)): te.match[fieldNameList[i]] = "" + str(fieldValueList[i]) te.insert()
def addLPMMatchEntry(self, tableName, fieldName, fieldValue, prefixLength, actionName, actionParamName, actionParamValue, priority=InternalConfig.DEFAULT_PRIORITY): te = sh.TableEntry(self, tableName)(action=actionName) te.match[fieldName] = "" + fieldValue + "/" + str(prefixLength) if ((actionParamName != None) and (actionParamValue != None)): te.action[actionParamName] = actionParamValue te.insert()
def addTernaryMatchEntry(self, tableName, fieldName, fieldValue, mask, actionName, actionParamName, actionParamValue, priority=InternalConfig.DEFAULT_PRIORITY): te = sh.TableEntry(self, tableName)(action=actionName) te.match[fieldName] = "" + fieldValue + " &&& " + mask te.action[actionParamName] = actionParamValue te.priority = priority te.insert()
def addExactMatchEntryWithMultipleActionParameter(self, tableName, fieldName, fieldValue, actionName, actionParamNameList, actionParamValueList): te = sh.TableEntry(self, tableName)(action=actionName) te.match[fieldName] = "" + fieldValue if (len(actionParamNameList) != len(actionParamValueList)): logger.info( "number of parameters for action and correspoding values are not matching in count" ) else: for i in range(0, len(actionParamNameList)): te.action[actionParamNameList[i]] = str( actionParamValueList[i]) te.insert()
def setupPortToPortDelayMetricsLevelCalculatorTables( dev, egressQueueDepthMetricsLevels): for metricsLevel in egressQueueDepthMetricsLevels: te = sh.TableEntry( dev, "IngressPipeImpl.path_delay_metrics_level_calculator_control_block.path_delay_metrics_level_calculator_table" )(action= "IngressPipeImpl.path_delay_metrics_level_calculator_control_block.set_delay_metrics_level" ) te.match["hdr.p2p_feedback.delay_event_data"] = str( metricsLevel.low) + ".." + str(metricsLevel.hi) #te.match[matachField2] = str(low)+".."+str(high) # "0..1024" te.action["delay_level"] = str(metricsLevel.level) te.action["weight"] = str(metricsLevel.weight) te.priority = int(intCoonfig.DEFAULT_PRIORITY) te.insert() return
def removeLPMMatchEntryWithGroupAction( self, tableName, fieldName, fieldValue, prefixLength, actionName, actionParamName, actionParamValue, groupID=None, priority=InternalConfig.DEFAULT_PRIORITY): te = sh.TableEntry(self, tableName) te.match[fieldName] = "" + fieldValue + "/" + str(prefixLength) if ((actionParamName != None) and (actionParamValue != None)): te.action[actionParamName] = actionParamValue # te.priority = priority if (groupID != None): te.group_id = groupID te.delete()
def addLPMMatchEntryWithGroupAction(self, tableName, fieldName, fieldValue, prefixLength, actionName, actionParamName, actionParamValue, groupID=None, priority=None): te = sh.TableEntry(self, tableName) te.match[fieldName] = "" + fieldValue + "/" + str(prefixLength) if ((actionParamName != None) and (actionParamValue != None)): te.action[actionParamName] = actionParamValue if priority != None: te.priority = priority if (groupID != None): te.group_id = groupID te.insert()
def addRangeMatchEntry(self, tableName, actionName, actionParamName, actionParamValue, matachField1, matchFieldValue1, matachField2, low, high): te = sh.TableEntry(self, tableName)(action=actionName) prefixLen = 10 - (int(math.floor(math.log(matchFieldValue1, 2)))) # if prefixLen <=0: # prefixLen = prefixLen+1 # else: # prefixLen = math.ceil(prefixLen) # if prefixLen>= 8: # logger.info("Ports can not be more than 8 bit. So exiting!!") # exit(1) # prefixLen = 8-prefixLen # te.match[matachField1] = str(matchFieldValue1)+"&&&"+ "0x00" te.match[matachField1] = str(0) + "/" + str(1) te.match[matachField2] = str(low) + ".." + str(high) # "0..1024" te.action[actionParamName] = str(actionParamValue) te.priority = int(actionParamValue) te.insert() return
def addLPMMatchEntryMultipleActionParameter( self, tableName, fieldName, fieldValue, prefixLength, actionName, actionParamNameList, actionParamValueList, groupID=None, priority=InternalConfig.DEFAULT_PRIORITY): te = sh.TableEntry(self, tableName)(action=actionName) te.match[fieldName] = "" + fieldValue + "/" + prefixLength if (len(actionParamNameList) != len(actionParamValueList)): logger.info( "number of parameters for action and correspoding values are not matching in count" ) else: for i in range(0, len(actionParamNameList)): te.action[actionParamNameList[i]] = str( actionParamValueList[i]) if (groupID != None): te.group_id = groupID te.insert()
def addExactMatchEntryWithoutActionParam(self, tableName, fieldName, fieldValue, actionName): te = sh.TableEntry(self, tableName)(action=actionName) te.match[fieldName] = "" + fieldValue te.insert()
def addExactMatchEntryNoAction(self, tableName, fieldName, fieldValue): te = sh.TableEntry(self, tableName)(action="NoAction") te.match[fieldName] = "" + fieldValue # te.action[actionParamName] = actionParamValue te.insert()
def test_table_indirect(self): member = sh.ActionProfileMember("ActProfWS")(member_id=1, action="actionA") member.action["param"] = "aa:bb:cc:dd:ee:ff" group = sh.ActionProfileGroup("ActProfWS")(group_id=1) group.add(member.member_id) expected_member = """ action_profile_id: 285237193 member_id: 1 action { action_id: 16783703 params { param_id: 1 value: "\\xaa\\xbb\\xcc\\xdd\\xee\\xff" } } """ expected_group = """ action_profile_id: 285237193 group_id: 1 members { member_id: 1 weight: 1 } """ expected_entry_1 = """ table_id: 33586946 match { field_id: 1 exact { value: "\\x0a\\x00\\x00\\x00" } } action { action_profile_member_id: 1 } """ expected_entry_2 = """ table_id: 33586946 match { field_id: 1 exact { value: "\\x0a\\x00\\x00\\x00" } } action { action_profile_group_id: 1 } """ expected_req = self.make_write_request( p4runtime_pb2.Update.INSERT, P4RuntimeEntity.action_profile_member, expected_member) member.insert() self.servicer.Write.assert_called_with(ProtoCmp(expected_req), ANY) expected_req = self.make_write_request( p4runtime_pb2.Update.INSERT, P4RuntimeEntity.action_profile_group, expected_group) group.insert() self.servicer.Write.assert_called_with(ProtoCmp(expected_req), ANY) te = sh.TableEntry("IndirectWS") te.match["header_test.field32"] = "10.0.0.0" te.member_id = member.member_id te.insert() expected_req = self.make_write_request(p4runtime_pb2.Update.INSERT, P4RuntimeEntity.table_entry, expected_entry_1) self.servicer.Write.assert_called_with(ProtoCmp(expected_req), ANY) te.group_id = group.group_id te.modify() expected_req = self.make_write_request(p4runtime_pb2.Update.MODIFY, P4RuntimeEntity.table_entry, expected_entry_2) self.servicer.Write.assert_called_with(ProtoCmp(expected_req), ANY)
def test_table_entry_lpm_dont_care(self): te = sh.TableEntry("LpmOne") with self.assertRaisesRegex(UserError, "LPM don't care match"): te.match["header_test.field32"] = "10.0.0.0/0"
def test_table_entry_range_invalid(self): te = sh.TableEntry("RangeOne") with self.assertRaisesRegex(UserError, "Invalid range match"): te.match["header_test.field32"] = "77..22"
def test_table_entry_range_dont_care(self): te = sh.TableEntry("RangeOne") with self.assertRaisesRegex(UserError, "range don't care match"): te.match["header_test.field32"] = "0..255.255.255.255"
def test_table_entry_ternary_dont_care(self): te = sh.TableEntry("TernaryOne") with self.assertRaisesRegex(UserError, "ternary don't care match"): te.match["header_test.field32"] = "10.0.0.0&&&0.0.0.0"