Search in sources :

Example 81 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.

the class NextObjectiveTranslatorTest method testRouteAndPushNextObjective.

/**
 * Test Route and Push Next Objective (set mac, set double vlan and output port).
 */
@Test
public void testRouteAndPushNextObjective() throws FabricPipelinerException {
    TrafficTreatment routeAndPushTreatment = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(HOST_MAC).setOutput(PORT_1).setVlanId(VLAN_100).pushVlan().setVlanId(VLAN_200).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(routeAndPushTreatment).withType(NextObjective.Type.SIMPLE).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorSimple.translate(nextObjective);
    PiAction piActionRouting = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
    PiAction piActionPush = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_DOUBLE_VLAN).withParameter(new PiActionParam(FabricConstants.INNER_VLAN_ID, VLAN_100.toShort())).withParameter(new PiActionParam(FabricConstants.OUTER_VLAN_ID, VLAN_200.toShort())).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build()).build();
    FlowRule expectedFlowRuleRouting = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE).withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionRouting).build()).build();
    FlowRule expectedFlowRuleDoublePush = DefaultFlowRule.builder().withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionPush).build()).forTable(FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRuleDoublePush).addFlowRule(expectedFlowRuleRouting).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 82 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.

the class IntProgrammableImpl method init.

@Override
public boolean init() {
    if (!setupBehaviour()) {
        return false;
    }
    PiActionParam transitIdParam = new PiActionParam(IntConstants.SWITCH_ID, ImmutableByteSequence.copyFrom(Integer.parseInt(deviceId.toString().substring(deviceId.toString().length() - 2))));
    TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(IntConstants.HDR_INT_IS_VALID, (byte) 0x01).build()).build();
    PiAction transitAction = PiAction.builder().withId(IntConstants.EGRESS_PROCESS_INT_TRANSIT_INIT_METADATA).withParameter(transitIdParam).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(transitAction).build();
    FlowRule transitFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(IntConstants.EGRESS_PROCESS_INT_TRANSIT_TB_INT_INSERT).build();
    flowRuleService.applyFlowRules(transitFlowRule);
    return true;
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 83 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.

the class IntProgrammableImpl method setSinkPort.

@Override
public boolean setSinkPort(PortNumber port) {
    if (!setupBehaviour()) {
        return false;
    }
    // process_set_source_sink.tb_set_sink
    PiCriterion egressCriterion = PiCriterion.builder().matchExact(IntConstants.HDR_STANDARD_METADATA_EGRESS_SPEC, port.toLong()).build();
    TrafficSelector sinkSelector = DefaultTrafficSelector.builder().matchPi(egressCriterion).build();
    PiAction setSinkAct = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_INT_SET_SINK).build();
    TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder().piTableAction(setSinkAct).build();
    FlowRule sinkFlowRule = DefaultFlowRule.builder().withSelector(sinkSelector).withTreatment(sinkTreatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SINK).build();
    flowRuleService.applyFlowRules(sinkFlowRule);
    return true;
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 84 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.

the class IntProgrammableImpl method setSourcePort.

@Override
public boolean setSourcePort(PortNumber port) {
    if (!setupBehaviour()) {
        return false;
    }
    // process_int_source_sink.tb_set_source for each host-facing port
    PiCriterion ingressCriterion = PiCriterion.builder().matchExact(IntConstants.HDR_STANDARD_METADATA_INGRESS_PORT, port.toLong()).build();
    TrafficSelector srcSelector = DefaultTrafficSelector.builder().matchPi(ingressCriterion).build();
    PiAction setSourceAct = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_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(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SOURCE).build();
    flowRuleService.applyFlowRules(srcFlowRule);
    return true;
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 85 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.

the class P4RuntimeGroupTest method testInvalidPiActionProfileMember.

@Test
public void testInvalidPiActionProfileMember() {
    PiActionParam param = new PiActionParam(PORT_PARAM_ID, "invalidString");
    PiAction piAction = PiAction.builder().withId(EGRESS_PORT_ACTION_ID).withParameter(param).build();
    PiActionProfileMember actionProfileMember = PiActionProfileMember.builder().forActionProfile(ACT_PROF_ID).withAction(piAction).withId(PiActionProfileMemberId.of(BASE_MEM_ID + 1)).build();
    P4RuntimeWriteClient.WriteRequest writeRequest = client.write(P4_DEVICE_ID, PIPECONF);
    writeRequest.insert(actionProfileMember);
    P4RuntimeWriteClient.WriteResponse response = writeRequest.submitSync();
    assertEquals(false, response.isSuccess());
    assertEquals(1, response.all().size());
    assertEquals("Wrong size for param 'port' of action 'set_egress_port', " + "expected no more than 2 bytes, but found 13", response.all().iterator().next().explanation());
}
Also used : P4RuntimeWriteClient(org.onosproject.p4runtime.api.P4RuntimeWriteClient) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Aggregations

PiAction (org.onosproject.net.pi.runtime.PiAction)117 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)74 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)69 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)68 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)57 TrafficSelector (org.onosproject.net.flow.TrafficSelector)57 Test (org.junit.Test)44 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)44 FlowRule (org.onosproject.net.flow.FlowRule)39 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)33 GroupDescription (org.onosproject.net.group.GroupDescription)22 List (java.util.List)15 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)14 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)14 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)13 PortNumber (org.onosproject.net.PortNumber)9 NextObjective (org.onosproject.net.flowobjective.NextObjective)9 GroupBucket (org.onosproject.net.group.GroupBucket)9 PiActionId (org.onosproject.net.pi.model.PiActionId)9 PiTableAction (org.onosproject.net.pi.runtime.PiTableAction)9