Search in sources :

Example 21 with PiAction

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

the class ForwardingObjectiveTranslatorTest method testAclNext.

/**
 * Test versatile flag of forwarding objective with next step.
 */
@Test
public void testAclNext() {
    // ACL 8-tuples
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).build();
    ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(NEXT_ID_1).add();
    ObjectiveTranslation result = translator.translate(fwd);
    List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
    List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
    assertEquals(1, flowRulesInstalled.size());
    assertTrue(groupsInstalled.isEmpty());
    FlowRule actualFlowRule = flowRulesInstalled.get(0);
    PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_NEXT_ID_ACL).withParameter(new PiActionParam(FabricConstants.NEXT_ID, NEXT_ID_1)).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
    assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 22 with PiAction

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

the class ForwardingObjectiveTranslator method aclRule.

private void aclRule(ForwardingObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    if (obj.nextId() == null && obj.treatment() != null) {
        final TrafficTreatment treatment = obj.treatment();
        final PortNumber outPort = outputPort(treatment);
        if (outPort != null && outPort.equals(PortNumber.CONTROLLER) && treatment.allInstructions().size() == 1) {
            final PiAction aclAction;
            if (treatment.clearedDeferred()) {
                aclAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_PUNT_TO_CPU).build();
            } else {
                // Action is SET_CLONE_SESSION_ID
                if (obj.op() == Objective.Operation.ADD) {
                    // Action is ADD, create clone group
                    final DefaultGroupDescription cloneGroup = createCloneGroup(obj.appId(), CLONE_TO_CPU_ID, outPort);
                    resultBuilder.addGroup(cloneGroup);
                }
                aclAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_CLONE_SESSION_ID).withParameter(new PiActionParam(FabricConstants.CLONE_ID, CLONE_TO_CPU_ID)).build();
            }
            final TrafficTreatment piTreatment = DefaultTrafficTreatment.builder().piTableAction(aclAction).build();
            resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_ACL_ACL, obj.selector(), piTreatment));
            return;
        }
    }
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(obj.selector());
    // Meta are used to signal the port type which can be edge or infra
    Byte portType = portType(obj);
    if (portType != null && !isSrMetadataSet(obj, PAIR_PORT)) {
        if (portType == PORT_TYPE_EDGE || portType == PORT_TYPE_INFRA) {
            selectorBuilder.matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_PORT_TYPE, (long) portType, PORT_TYPE_MASK).build());
        } else {
            throw new FabricPipelinerException(format("Port type '%s' is not allowed for table '%s'", portType, FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN), ObjectiveError.UNSUPPORTED);
        }
    }
    resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_ACL_ACL, selectorBuilder.build()));
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 23 with PiAction

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

the class PiGroupTranslatorImplTest method outputMember.

private static PiActionProfileMember outputMember(int portNum) throws ImmutableByteSequence.ByteSequenceTrimException {
    PiActionParam param = new PiActionParam(PORT, copyFrom(portNum).fit(PORT_BITWIDTH));
    PiAction piAction = PiAction.builder().withId(INGRESS_WCMP_CONTROL_SET_EGRESS_PORT).withParameter(param).build();
    return PiActionProfileMember.builder().forActionProfile(INGRESS_WCMP_CONTROL_WCMP_SELECTOR).withAction(piAction).withId(PiActionProfileMemberId.of(BASE_MEM_ID + portNum)).build();
}
Also used : PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 24 with PiAction

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

the class ActionCodec method encode.

@Override
protected P4RuntimeOuterClass.Action encode(PiAction piAction, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException, P4InfoBrowser.NotFoundException {
    final int actionId = browser.actions().getByName(piAction.id().toString()).getPreamble().getId();
    final P4RuntimeOuterClass.Action.Builder actionMsgBuilder = P4RuntimeOuterClass.Action.newBuilder().setActionId(actionId);
    for (PiActionParam p : piAction.parameters()) {
        final P4InfoOuterClass.Action.Param paramInfo = browser.actionParams(actionId).getByName(p.id().toString());
        final ByteString paramValue = ByteString.copyFrom(p.value().asReadOnlyBuffer());
        if (!browser.isTypeString(paramInfo.getTypeName())) {
            // Check size only if the param type is not a sdn_string
            assertSize(format("param '%s' of action '%s'", p.id(), piAction.id()), paramValue, paramInfo.getBitwidth());
        }
        actionMsgBuilder.addParams(P4RuntimeOuterClass.Action.Param.newBuilder().setParamId(paramInfo.getId()).setValue(paramValue).build());
    }
    return actionMsgBuilder.build();
}
Also used : PiAction(org.onosproject.net.pi.runtime.PiAction) ByteString(com.google.protobuf.ByteString) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam)

Example 25 with PiAction

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

the class MyTunnelApp method insertTunnelIngressRule.

/**
 * Generates and insert a flow rule to perform the tunnel INGRESS function
 * for the given switch, destination IP address and tunnel ID.
 *
 * @param switchId  switch ID
 * @param dstIpAddr IP address to forward inside the tunnel
 * @param tunId     tunnel ID
 */
private void insertTunnelIngressRule(DeviceId switchId, IpAddress dstIpAddr, int tunId) {
    PiTableId tunnelIngressTableId = PiTableId.of("c_ingress.t_tunnel_ingress");
    // Longest prefix match on IPv4 dest address.
    PiMatchFieldId ipDestMatchFieldId = PiMatchFieldId.of("hdr.ipv4.dst_addr");
    PiCriterion match = PiCriterion.builder().matchLpm(ipDestMatchFieldId, dstIpAddr.toOctets(), 32).build();
    PiActionParam tunIdParam = new PiActionParam(PiActionParamId.of("tun_id"), tunId);
    PiActionId ingressActionId = PiActionId.of("c_ingress.my_tunnel_ingress");
    PiAction action = PiAction.builder().withId(ingressActionId).withParameter(tunIdParam).build();
    log.info("Inserting INGRESS rule on switch {}: table={}, match={}, action={}", switchId, tunnelIngressTableId, match, action);
    insertPiFlowRule(switchId, tunnelIngressTableId, match, action);
}
Also used : PiActionId(org.onosproject.net.pi.model.PiActionId) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiTableId(org.onosproject.net.pi.model.PiTableId) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiAction (org.onosproject.net.pi.runtime.PiAction)57 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)42 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)39 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)39 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)31 TrafficSelector (org.onosproject.net.flow.TrafficSelector)31 Test (org.junit.Test)25 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)19 FlowRule (org.onosproject.net.flow.FlowRule)19 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)17 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)10 GroupDescription (org.onosproject.net.group.GroupDescription)10 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)6 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)6 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)5 NextObjective (org.onosproject.net.flowobjective.NextObjective)5 GroupBucket (org.onosproject.net.group.GroupBucket)5 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)5