use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class CriterionCodecTest method matchPiTypeDecodingTest.
/**
* Tests protocol-independent type criterion decoding.
*/
@Test
public void matchPiTypeDecodingTest() throws IOException {
Criterion criterion = getCriterion("PiCriterion.json");
Assert.assertThat(criterion.type(), is(Criterion.Type.PROTOCOL_INDEPENDENT));
Collection<PiFieldMatch> piFieldMatches = ((PiCriterion) criterion).fieldMatches();
for (PiFieldMatch piFieldMatch : piFieldMatches) {
switch(piFieldMatch.type()) {
case EXACT:
Assert.assertThat(piFieldMatch.fieldId().id(), is("ingress_port"));
Assert.assertThat(((PiExactFieldMatch) piFieldMatch).value(), is(copyFrom((byte) 0x10)));
break;
case LPM:
Assert.assertThat(piFieldMatch.fieldId().id(), is("src_addr"));
Assert.assertThat(((PiLpmFieldMatch) piFieldMatch).value(), is(copyFrom(0xa010101)));
Assert.assertThat(((PiLpmFieldMatch) piFieldMatch).prefixLength(), is(24));
break;
case TERNARY:
Assert.assertThat(piFieldMatch.fieldId().id(), is("dst_addr"));
Assert.assertThat(((PiTernaryFieldMatch) piFieldMatch).value(), is(copyFrom(0xa010101)));
Assert.assertThat(((PiTernaryFieldMatch) piFieldMatch).mask(), is(copyFrom(0xfffffff)));
break;
case RANGE:
Assert.assertThat(piFieldMatch.fieldId().id(), is("egress_port"));
Assert.assertThat(((PiRangeFieldMatch) piFieldMatch).highValue(), is(copyFrom((byte) 0x20)));
Assert.assertThat(((PiRangeFieldMatch) piFieldMatch).lowValue(), is(copyFrom((byte) 0x10)));
break;
case OPTIONAL:
Assert.assertThat(piFieldMatch.fieldId().id(), is("eth_dst"));
Assert.assertThat(((PiOptionalFieldMatch) piFieldMatch).value(), is(copyFrom(new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 })));
break;
default:
Assert.fail();
}
}
}
use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class IntProgrammableImpl method populateInstTableEntry.
private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId, int matchValue, PiActionId actionId, ApplicationId appId) {
PiCriterion instCriterion = PiCriterion.builder().matchExact(matchFieldId, matchValue).build();
TrafficSelector instSelector = DefaultTrafficSelector.builder().matchPi(instCriterion).build();
PiAction instAction = PiAction.builder().withId(actionId).build();
TrafficTreatment instTreatment = DefaultTrafficTreatment.builder().piTableAction(instAction).build();
FlowRule instFlowRule = DefaultFlowRule.builder().withSelector(instSelector).withTreatment(instTreatment).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(tableId).fromApp(appId).build();
flowRuleService.applyFlowRules(instFlowRule);
}
use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class FabricIntProgrammable method setSourcePort.
@Override
public boolean setSourcePort(PortNumber port) {
if (!setupBehaviour()) {
return false;
}
PiCriterion ingressCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_IG_PORT, port.toLong()).build();
TrafficSelector srcSelector = DefaultTrafficSelector.builder().matchPi(ingressCriterion).build();
PiAction setSourceAct = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SOURCE).build();
TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder().piTableAction(setSourceAct).build();
FlowRule srcFlowRule = DefaultFlowRule.builder().withSelector(srcSelector).withTreatment(srcTreatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE).build();
flowRuleService.applyFlowRules(srcFlowRule);
return true;
}
use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class FabricBngProgrammable method setupPuntToCpu.
/**
* Set the punt to CPU rules of the BNG from a specific Application ID.
*
* @param appId Application ID asking to recive BNG control plane packets.
*/
private void setupPuntToCpu(ApplicationId appId) {
for (Criterion c : PuntCpuCriterionFactory.getAllPuntCriterion()) {
FlowRule flPuntCpu = buildTPppoeCpFlowRule((PiCriterion) c, appId);
flowRuleService.applyFlowRules(flPuntCpu);
}
}
use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class NextObjectiveTranslator method egressVlan.
private void egressVlan(PortNumber outPort, NextObjective obj, Instruction popVlanInst, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
final VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) criterion(obj.meta(), Criterion.Type.VLAN_VID);
final PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
final TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(vlanIdCriterion.vlanId()).build();
final TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
if (popVlanInst == null) {
treatmentBuilder.pushVlan();
} else {
treatmentBuilder.popVlan();
}
resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN, selector, treatmentBuilder.build()));
}
Aggregations