use of org.onosproject.net.pi.runtime.PiTableEntry in project up4 by omec-project.
the class Up4NorthComponentTest method tunnelPeerInsertionTest.
// ------------------- INSERTION TESTS -------------------------------------
@Test
public void tunnelPeerInsertionTest() throws Exception {
PiTableEntry entry = TestImplConstants.UP4_TUNNEL_PEER;
insertionTest(entry);
assertThat(mockUp4Service.readAll(UpfEntityType.TUNNEL_PEER).size(), equalTo(1));
}
use of org.onosproject.net.pi.runtime.PiTableEntry in project onos by opennetworkinglab.
the class PiFlowRuleTranslatorImpl method translate.
/**
* Returns a PI table entry equivalent to the given flow rule, for the given
* pipeconf and device.
*
* @param rule flow rule
* @param pipeconf pipeconf
* @param device device
* @return PI table entry
* @throws PiTranslationException if the flow rule cannot be translated
*/
static PiTableEntry translate(FlowRule rule, PiPipeconf pipeconf, Device device) throws PiTranslationException {
PiPipelineModel pipelineModel = pipeconf.pipelineModel();
// Retrieve interpreter, if any.
final PiPipelineInterpreter interpreter = getInterpreterOrNull(device, pipeconf);
// Get table model.
final PiTableId piTableId = translateTableId(rule.table(), interpreter);
final PiTableModel tableModel = getTableModel(piTableId, pipelineModel);
// Translate selector.
final PiMatchKey piMatchKey;
final boolean needPriority;
if (rule.selector().criteria().isEmpty()) {
piMatchKey = PiMatchKey.EMPTY;
needPriority = false;
} else {
final Collection<PiFieldMatch> fieldMatches = translateFieldMatches(interpreter, rule.selector(), tableModel);
piMatchKey = PiMatchKey.builder().addFieldMatches(fieldMatches).build();
// FIXME: P4Runtime limit
// Need to ignore priority if no TCAM lookup match field
needPriority = tableModel.matchFields().stream().anyMatch(match -> match.matchType() == PiMatchType.TERNARY || match.matchType() == PiMatchType.RANGE || match.matchType() == PiMatchType.OPTIONAL);
}
// Translate treatment.
final PiTableAction piTableAction = translateTreatment(rule.treatment(), interpreter, piTableId, pipelineModel);
// Build PI entry.
final PiTableEntry.Builder tableEntryBuilder = PiTableEntry.builder();
tableEntryBuilder.forTable(piTableId).withMatchKey(piMatchKey);
if (piTableAction != null) {
tableEntryBuilder.withAction(piTableAction);
}
if (needPriority) {
// FIXME: move priority check to P4Runtime driver.
final int newPriority;
if (rule.priority() > MAX_PI_PRIORITY) {
log.warn("Flow rule priority too big, setting translated priority to max value {}: {}", MAX_PI_PRIORITY, rule);
newPriority = MAX_PI_PRIORITY;
} else {
newPriority = MIN_PI_PRIORITY + rule.priority();
}
tableEntryBuilder.withPriority(newPriority);
}
if (!rule.isPermanent()) {
if (tableModel.supportsAging()) {
tableEntryBuilder.withTimeout(rule.timeout());
} else {
log.debug("Flow rule is temporary, but table '{}' doesn't support " + "aging, translating to permanent.", tableModel.id());
}
}
return tableEntryBuilder.build();
}
use of org.onosproject.net.pi.runtime.PiTableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testEncodeWithNoAction.
@Test
public void testEncodeWithNoAction() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntryWithoutAction, null, defaultPipeconf);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntryWithoutAction, decodedPiTableEntry).testEquals();
// Table ID.
int p4InfoTableId = browser.tables().getByName(tableId.id()).getPreamble().getId();
int encodedTableId = tableEntryMsg.getTableId();
assertThat(encodedTableId, is(p4InfoTableId));
// Ternary match.
byte[] encodedTernaryMatchValue = tableEntryMsg.getMatch(0).getTernary().getValue().toByteArray();
assertThat(encodedTernaryMatchValue, is(ethAddr.asArray()));
// no action
assertThat(tableEntryMsg.hasAction(), is(false));
// Counter
CounterData counterData = tableEntryMsg.getCounterData();
PiCounterCellData encodedCounterData = new PiCounterCellData(counterData.getPacketCount(), counterData.getByteCount());
assertThat(encodedCounterData, is(counterCellData));
// TODO: improve, assert other field match types (ternary, LPM)
}
use of org.onosproject.net.pi.runtime.PiTableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testTableEntryEncoderWithTranslations.
@Test
public void testTableEntryEncoderWithTranslations() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntry2, null, defaultPipeconf2);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf2);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntry2, decodedPiTableEntry).testEquals();
// Check the exact match with string
byte[] encodedExactMatchValueString = tableEntryMsg.getMatch(1).getExact().getValue().toByteArray();
assertThat(encodedExactMatchValueString, is(ethAddrString.asArray()));
Action actionMsg = tableEntryMsg.getAction().getAction();
// Check action param value with string
byte[] encodedActionParamString = actionMsg.getParams(0).getValue().toByteArray();
assertThat(encodedActionParamString, is(portValueString.asArray()));
TableEntry tableEntryMsg1 = Codecs.CODECS.tableEntry().encode(piTableEntry3, null, defaultPipeconf2);
PiTableEntry decodedPiTableEntry1 = Codecs.CODECS.tableEntry().decode(tableEntryMsg1, null, defaultPipeconf2);
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntry3, decodedPiTableEntry1).testEquals();
}
use of org.onosproject.net.pi.runtime.PiTableEntry in project onos by opennetworkinglab.
the class TableEntryEncoderTest method testTableEntryEncoderWithoutOptionalField.
@Test
public void testTableEntryEncoderWithoutOptionalField() throws Exception {
TableEntry tableEntryMsg = Codecs.CODECS.tableEntry().encode(piTableEntryWithoutOptionalField, null, defaultPipeconf2);
PiTableEntry decodedPiTableEntry = Codecs.CODECS.tableEntry().decode(tableEntryMsg, null, defaultPipeconf2);
// Table ID.
int p4InfoTableId = browser2.tables().getByName(tableId.id()).getPreamble().getId();
int encodedTableId = tableEntryMsg.getTableId();
assertThat(encodedTableId, is(p4InfoTableId));
// Test equality for decoded entry.
new EqualsTester().addEqualityGroup(piTableEntryWithoutOptionalField, decodedPiTableEntry).testEquals();
// no optional field
assertThat(tableEntryMsg.getMatchCount(), is(3));
assertThat(tableEntryMsg.getMatchList().stream().map(P4RuntimeOuterClass.FieldMatch::getFieldMatchTypeCase).collect(Collectors.toList()), not(hasItem(P4RuntimeOuterClass.FieldMatch.FieldMatchTypeCase.OPTIONAL)));
}
Aggregations