Search in sources :

Example 1 with PiActionProfileGroupId

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

the class NextObjectiveTranslatorTest method testMplsHashedOutput.

/**
 * Test program mpls ecmp output group for Hashed table.
 */
@Test
public void testMplsHashedOutput() throws Exception {
    TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(SPINE1_MAC).pushMpls().copyTtlOut().setMpls(MPLS_10).popVlan().setOutput(PORT_1).build();
    TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(SPINE2_MAC).pushMpls().copyTtlOut().setMpls(MPLS_10).popVlan().setOutput(PORT_2).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).withMeta(VLAN_META).addTreatment(treatment1).addTreatment(treatment2).withType(NextObjective.Type.HASHED).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
    // Expected hashed table flow rule.
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
    PiActionProfileGroupId actionGroupId = PiActionProfileGroupId.of(NEXT_ID_1);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(actionGroupId).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_HASHED).withSelector(nextIdSelector).withTreatment(treatment).build();
    // First egress rule - port1
    PortNumber outPort = outputPort(treatment1);
    PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
    TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    PiAction piActionForEgressVlan = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
    TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
    FlowRule expectedEgressVlanPopRule1 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    // Second egress rule - port2
    outPort = outputPort(treatment2);
    egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
    selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    FlowRule expectedEgressVlanPopRule2 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    // Expected group
    PiAction piAction1 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, SPINE1_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
    PiAction piAction2 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, SPINE2_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_2.toLong())).build();
    treatment1 = DefaultTrafficTreatment.builder().piTableAction(piAction1).build();
    treatment2 = DefaultTrafficTreatment.builder().piTableAction(piAction2).build();
    List<TrafficTreatment> treatments = ImmutableList.of(treatment1, treatment2);
    List<GroupBucket> buckets = treatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    PiGroupKey groupKey = new PiGroupKey(FabricConstants.FABRIC_INGRESS_NEXT_HASHED, FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR, NEXT_ID_1);
    GroupDescription expectedGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.SELECT, groupBuckets, groupKey, NEXT_ID_1, APP_ID);
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRule).addFlowRule(vlanMetaFlowRule).addFlowRule(mplsFlowRule).addGroup(expectedGroup).addFlowRule(expectedEgressVlanPopRule1).addFlowRule(expectedEgressVlanPopRule2).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) PiAction(org.onosproject.net.pi.runtime.PiAction) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) Test(org.junit.Test)

Example 2 with PiActionProfileGroupId

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

the class DecodeInstructionCodecHelper method decodePi.

/**
 * Decodes a protocol-independent instruction.
 *
 * @return instruction object decoded from the JSON
 * @throws IllegalArgumentException if the JSON is invalid
 */
private Instruction decodePi() {
    String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE), InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText();
    if (subType.equals(PiTableAction.Type.ACTION.name())) {
        PiActionId piActionId = PiActionId.of(nullIsIllegal(json.get(InstructionCodec.PI_ACTION_ID), InstructionCodec.PI_ACTION_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asText());
        JsonNode params = json.get(InstructionCodec.PI_ACTION_PARAMS);
        PiAction.Builder builder = PiAction.builder();
        PiActionParam piActionParam;
        PiActionParamId piActionParamId;
        if (params != null) {
            for (Map.Entry<String, String> param : ((Map<String, String>) (context.mapper().convertValue(params, Map.class))).entrySet()) {
                piActionParamId = PiActionParamId.of(param.getKey());
                piActionParam = new PiActionParam(piActionParamId, ImmutableByteSequence.copyFrom(HexString.fromHexString(param.getValue(), null)));
                builder.withParameter(piActionParam);
            }
        }
        return Instructions.piTableAction(builder.withId(piActionId).build());
    } else if (subType.equals(PiTableAction.Type.ACTION_PROFILE_GROUP_ID.name())) {
        PiActionProfileGroupId piActionGroupId = PiActionProfileGroupId.of(nullIsIllegal(json.get(InstructionCodec.PI_ACTION_PROFILE_GROUP_ID), InstructionCodec.PI_ACTION_PROFILE_GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
        return Instructions.piTableAction(piActionGroupId);
    } else if (subType.equals(PiTableAction.Type.ACTION_PROFILE_MEMBER_ID.name())) {
        PiActionProfileMemberId piActionProfileMemberId = PiActionProfileMemberId.of(nullIsIllegal(json.get(InstructionCodec.PI_ACTION_PROFILE_MEMBER_ID), InstructionCodec.PI_ACTION_PROFILE_MEMBER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
        return Instructions.piTableAction(piActionProfileMemberId);
    }
    // TODO: implement JSON decoder for ACTION_SET
    throw new IllegalArgumentException("Protocol-independent Instruction subtype " + subType + " is not supported");
}
Also used : PiActionProfileMemberId(org.onosproject.net.pi.runtime.PiActionProfileMemberId) PiActionId(org.onosproject.net.pi.model.PiActionId) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Map(java.util.Map) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 3 with PiActionProfileGroupId

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

the class EncodeInstructionCodecHelper method encodePi.

/**
 * Encode a protocol-independent instruction.
 *
 * @param result json node that the instruction attributes are added to
 */
private void encodePi(ObjectNode result) {
    PiInstruction piInstruction = (PiInstruction) instruction;
    result.put(InstructionCodec.SUBTYPE, piInstruction.action().type().name());
    switch(piInstruction.action().type()) {
        case ACTION:
            final PiAction piAction = (PiAction) piInstruction.action();
            result.put(InstructionCodec.PI_ACTION_ID, piAction.id().id());
            final ObjectNode jsonActionParams = context.mapper().createObjectNode();
            for (PiActionParam actionParam : piAction.parameters()) {
                jsonActionParams.put(actionParam.id().id(), HexString.toHexString(actionParam.value().asArray(), null));
            }
            result.set(InstructionCodec.PI_ACTION_PARAMS, jsonActionParams);
            break;
        case ACTION_PROFILE_GROUP_ID:
            final PiActionProfileGroupId groupId = (PiActionProfileGroupId) piInstruction.action();
            result.put(InstructionCodec.PI_ACTION_PROFILE_GROUP_ID, groupId.id());
            break;
        case ACTION_PROFILE_MEMBER_ID:
            final PiActionProfileMemberId memberId = (PiActionProfileMemberId) piInstruction.action();
            result.put(InstructionCodec.PI_ACTION_PROFILE_MEMBER_ID, memberId.id());
            break;
        // TODO: implement JSON encoder for ACTION_SET
        default:
            throw new IllegalArgumentException("Cannot convert protocol-independent subtype of" + piInstruction.action().type().name());
    }
}
Also used : PiActionProfileMemberId(org.onosproject.net.pi.runtime.PiActionProfileMemberId) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 4 with PiActionProfileGroupId

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

the class InstructionJsonMatcher method matchPiInstruction.

/**
 * Matches the contents of a protocol-independent instruction.
 *
 * @param instructionJson JSON instruction to match
 * @param description Description object used for recording errors
 * @return true if contents match, false otherwise
 */
private boolean matchPiInstruction(JsonNode instructionJson, Description description) {
    PiInstruction instructionToMatch = (PiInstruction) instruction;
    final String jsonSubtype = instructionJson.get("subtype").textValue();
    if (!instructionToMatch.action().type().name().equals(jsonSubtype)) {
        description.appendText("subtype was " + jsonSubtype);
        return false;
    }
    final String jsonType = instructionJson.get("type").textValue();
    if (!instructionToMatch.type().name().equals(jsonType)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    switch(instructionToMatch.action().type()) {
        case ACTION:
            if (!Objects.equals(instructionJson.get("actionId").textValue(), ((PiAction) instructionToMatch.action()).id().id())) {
                description.appendText("action was " + ((PiAction) instructionToMatch.action()).id().id());
                return false;
            }
            Collection<PiActionParam> piActionParams = ((PiAction) instructionToMatch.action()).parameters();
            JsonNode jsonParams = instructionJson.get("actionParams");
            for (PiActionParam actionParam : piActionParams) {
                if (!Objects.equals(copyFrom(HexString.fromHexString(jsonParams.get(actionParam.id().id()).textValue(), null)), actionParam.value())) {
                    description.appendText("action param value was " + actionParam.value());
                    return false;
                }
            }
            break;
        case ACTION_PROFILE_GROUP_ID:
            if (!Objects.equals(instructionJson.get("groupId").asInt(), ((PiActionProfileGroupId) instructionToMatch.action()).id())) {
                description.appendText("action profile group id was " + ((PiActionProfileGroupId) instructionToMatch.action()).id());
                return false;
            }
            break;
        case ACTION_PROFILE_MEMBER_ID:
            if (!Objects.equals(instructionJson.get("memberId").asInt(), ((PiActionProfileMemberId) instructionToMatch.action()).id())) {
                description.appendText("action profile member id was " + ((PiActionProfileMemberId) instructionToMatch.action()).id());
                return false;
            }
            break;
        default:
            description.appendText("type was " + jsonType);
            return false;
    }
    return true;
}
Also used : PiActionProfileMemberId(org.onosproject.net.pi.runtime.PiActionProfileMemberId) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 5 with PiActionProfileGroupId

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

the class NextObjectiveTranslatorTest method testHashedOutput.

/**
 * Test program ecmp output group for Hashed table.
 */
@Test
public void testHashedOutput() throws Exception {
    PiAction piAction1 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).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 piAction2 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).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();
    TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().piTableAction(piAction1).build();
    TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().piTableAction(piAction2).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).withMeta(VLAN_META).addTreatment(treatment1).addTreatment(treatment2).withType(NextObjective.Type.HASHED).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
    // Expected hashed table flow rule.
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
    PiActionProfileGroupId actionGroupId = PiActionProfileGroupId.of(NEXT_ID_1);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(actionGroupId).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_HASHED).withSelector(nextIdSelector).withTreatment(treatment).build();
    // Expected group
    List<TrafficTreatment> treatments = ImmutableList.of(treatment1, treatment2);
    List<GroupBucket> buckets = treatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    PiGroupKey groupKey = new PiGroupKey(FabricConstants.FABRIC_INGRESS_NEXT_HASHED, FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR, NEXT_ID_1);
    GroupDescription expectedGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.SELECT, groupBuckets, groupKey, NEXT_ID_1, APP_ID);
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRule).addFlowRule(vlanMetaFlowRule).addGroup(expectedGroup).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) PiAction(org.onosproject.net.pi.runtime.PiAction) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) Test(org.junit.Test)

Aggregations

PiAction (org.onosproject.net.pi.runtime.PiAction)5 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)5 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)5 PiActionProfileMemberId (org.onosproject.net.pi.runtime.PiActionProfileMemberId)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Test (org.junit.Test)2 HexString (org.onlab.util.HexString)2 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)2 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 FlowRule (org.onosproject.net.flow.FlowRule)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)2 PiInstruction (org.onosproject.net.flow.instructions.PiInstruction)2 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)2 NextObjective (org.onosproject.net.flowobjective.NextObjective)2 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)2 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)2 GroupBucket (org.onosproject.net.group.GroupBucket)2