org.onosproject.net.pi.runtime.PiActionProfileGroupId Java Examples
The following examples show how to use
org.onosproject.net.pi.runtime.PiActionProfileGroupId.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Ipv6RoutingComponent.java From ngsdn-tutorial with Apache License 2.0 | 6 votes |
/** * Creates a routing flow rule that matches on the given IPv6 prefix and * executes the given group ID (created before). * * @param deviceId the device where flow rule will be installed * @param ip6Prefix the IPv6 prefix * @param groupId the group ID * @return a flow rule */ private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix, int groupId) { final String tableId = "IngressPipeImpl.routing_v6_table"; final PiCriterion match = PiCriterion.builder() .matchLpm( PiMatchFieldId.of("hdr.ipv6.dst_addr"), ip6Prefix.address().toOctets(), ip6Prefix.prefixLength()) .build(); final PiTableAction action = PiActionProfileGroupId.of(groupId); return Utils.buildFlowRule( deviceId, appId, tableId, match, action); }
Example #2
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 6 votes |
/** * Creates a routing flow rule that matches on the given IPv6 prefix and * executes the given group ID (created before). * * @param deviceId the device where flow rule will be installed * @param ip6Prefix the IPv6 prefix * @param groupId the group ID * @return a flow rule */ private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix, int groupId) { // TODO EXERCISE 3 // Modify P4Runtime entity names to match content of P4Info file (look // for the fully qualified name of tables, match fields, and actions. // ---- START SOLUTION ---- final String tableId = "IngressPipeImpl.l3_table"; final PiCriterion match = PiCriterion.builder() .matchLpm( PiMatchFieldId.of("hdr.ipv6.dst_addr"), ip6Prefix.address().toOctets(), ip6Prefix.prefixLength()) .build(); final PiTableAction action = PiActionProfileGroupId.of(groupId); // ---- END SOLUTION ---- return Utils.buildFlowRule( deviceId, appId, tableId, match, action); }
Example #3
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 6 votes |
/** * Creates a routing flow rule that matches on the given IPv6 prefix and * executes the given group ID (created before). * * @param deviceId the device where flow rule will be installed * @param ip6Prefix the IPv6 prefix * @param groupId the group ID * @return a flow rule */ private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix, int groupId) { // TODO EXERCISE 3 // Modify P4Runtime entity names to match content of P4Info file (look // for the fully qualified name of tables, match fields, and actions. // ---- START SOLUTION ---- final String tableId = "MODIFY ME"; final PiCriterion match = PiCriterion.builder() .matchLpm( PiMatchFieldId.of("MODIFY ME"), ip6Prefix.address().toOctets(), ip6Prefix.prefixLength()) .build(); final PiTableAction action = PiActionProfileGroupId.of(groupId); // ---- END SOLUTION ---- return Utils.buildFlowRule( deviceId, appId, tableId, match, action); }
Example #4
Source File: ActionProfileGroupCodec.java From onos with Apache License 2.0 | 6 votes |
@Override public PiActionProfileGroup decode( ActionProfileGroup msg, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { final PiActionProfileGroup.Builder piGroupBuilder = PiActionProfileGroup.builder() .withActionProfileId(PiActionProfileId.of( browser.actionProfiles() .getById(msg.getActionProfileId()) .getPreamble().getName())) .withId(PiActionProfileGroupId.of(msg.getGroupId())) .withMaxSize(msg.getMaxSize()); msg.getMembersList().forEach(m -> { final int weight; if (m.getWeight() < 1) { log.warn("Decoding group with invalid weight '{}', will set to 1", m.getWeight()); weight = 1; } else { weight = m.getWeight(); } piGroupBuilder.addMember( PiActionProfileMemberId.of(m.getMemberId()), weight); }); return piGroupBuilder.build(); }
Example #5
Source File: TableEntryCodec.java From onos with Apache License 2.0 | 6 votes |
private PiTableAction decodeTableActionMsg( P4RuntimeOuterClass.TableAction tableActionMsg, PiPipeconf pipeconf) throws CodecException { P4RuntimeOuterClass.TableAction.TypeCase typeCase = tableActionMsg.getTypeCase(); switch (typeCase) { case ACTION: P4RuntimeOuterClass.Action actionMsg = tableActionMsg.getAction(); return CODECS.action().decode( actionMsg, null, pipeconf); case ACTION_PROFILE_GROUP_ID: return PiActionProfileGroupId.of( tableActionMsg.getActionProfileGroupId()); case ACTION_PROFILE_MEMBER_ID: return PiActionProfileMemberId.of( tableActionMsg.getActionProfileMemberId()); default: throw new CodecException( format("Decoding of table action type %s not implemented", typeCase.name())); } }
Example #6
Source File: NextObjectiveTranslator.java From onos with Apache License 2.0 | 6 votes |
private void hashedNext(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException { if (!capabilities.hasHashedTable()) { simpleNext(obj, resultBuilder, true); return; } // Updated result builder with hashed group. final int groupId = selectGroup(obj, resultBuilder); if (isGroupModifyOp(obj)) { // No changes to flow rules. return; } final TrafficSelector selector = nextIdSelector(obj.id()); final TrafficTreatment treatment = DefaultTrafficTreatment.builder() .piTableAction(PiActionProfileGroupId.of(groupId)) .build(); resultBuilder.addFlowRule(flowRule( obj, FabricConstants.FABRIC_INGRESS_NEXT_HASHED, selector, treatment)); }
Example #7
Source File: InstructionCodecTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests the encoding of protocol-independent instructions. */ @Test public void piInstructionEncodingTest() { PiActionId actionId = PiActionId.of("set_egress_port"); PiActionParamId actionParamId = PiActionParamId.of("port"); PiActionParam actionParam = new PiActionParam(actionParamId, ImmutableByteSequence.copyFrom(10)); PiTableAction action = PiAction.builder().withId(actionId).withParameter(actionParam).build(); final PiInstruction actionInstruction = Instructions.piTableAction(action); final ObjectNode actionInstructionJson = instructionCodec.encode(actionInstruction, context); assertThat(actionInstructionJson, matchesInstruction(actionInstruction)); PiTableAction actionGroupId = PiActionProfileGroupId.of(10); final PiInstruction actionGroupIdInstruction = Instructions.piTableAction(actionGroupId); final ObjectNode actionGroupIdInstructionJson = instructionCodec.encode(actionGroupIdInstruction, context); assertThat(actionGroupIdInstructionJson, matchesInstruction(actionGroupIdInstruction)); PiTableAction actionProfileMemberId = PiActionProfileMemberId.of(10); final PiInstruction actionProfileMemberIdInstruction = Instructions.piTableAction(actionProfileMemberId); final ObjectNode actionProfileMemberIdInstructionJson = instructionCodec.encode(actionProfileMemberIdInstruction, context); assertThat(actionProfileMemberIdInstructionJson, matchesInstruction(actionProfileMemberIdInstruction)); }
Example #8
Source File: ActionProfileGroupCodec.java From onos with Apache License 2.0 | 5 votes |
private ActionProfileGroup.Builder keyMsgBuilder( PiActionProfileId actProfId, PiActionProfileGroupId groupId, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { return ActionProfileGroup.newBuilder() .setGroupId(groupId.id()) .setActionProfileId(browser.actionProfiles() .getByName(actProfId.id()) .getPreamble().getId()); }
Example #9
Source File: TableEntryCodec.java From onos with Apache License 2.0 | 5 votes |
private P4RuntimeOuterClass.TableAction encodePiTableAction( PiTableAction piTableAction, PiPipeconf pipeconf) throws CodecException { checkNotNull(piTableAction, "Cannot encode null PiTableAction"); final P4RuntimeOuterClass.TableAction.Builder tableActionMsgBuilder = P4RuntimeOuterClass.TableAction.newBuilder(); switch (piTableAction.type()) { case ACTION: P4RuntimeOuterClass.Action theAction = CODECS.action() .encode((PiAction) piTableAction, null, pipeconf); tableActionMsgBuilder.setAction(theAction); break; case ACTION_PROFILE_GROUP_ID: tableActionMsgBuilder.setActionProfileGroupId( ((PiActionProfileGroupId) piTableAction).id()); break; case ACTION_PROFILE_MEMBER_ID: tableActionMsgBuilder.setActionProfileMemberId( ((PiActionProfileMemberId) piTableAction).id()); break; default: throw new CodecException( format("Building of table action type %s not implemented", piTableAction.type())); } return tableActionMsgBuilder.build(); }
Example #10
Source File: PiInstruction.java From onos with Apache License 2.0 | 5 votes |
@Override public String toString() { switch (tableAction.type()) { case ACTION_PROFILE_GROUP_ID: return "GROUP:0x" + Integer.toHexString(((PiActionProfileGroupId) tableAction).id()); case ACTION_PROFILE_MEMBER_ID: return "GROUP_MEMBER:0x" + Integer.toHexString(((PiActionProfileMemberId) tableAction).id()); default: return tableAction.toString(); } }
Example #11
Source File: EncodeInstructionCodecHelper.java From onos with Apache License 2.0 | 5 votes |
/** * 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; default: throw new IllegalArgumentException("Cannot convert protocol-independent subtype of" + piInstruction.action().type().name()); } }
Example #12
Source File: InstructionCodecTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests the decoding of protocol-independent instructions. */ @Test public void piInstructionDecodingTest() throws IOException { Instruction actionInstruction = getInstruction("PiActionInstruction.json"); Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT)); PiTableAction action = ((PiInstruction) actionInstruction).action(); Assert.assertThat(action.type(), is(PiTableAction.Type.ACTION)); Assert.assertThat(((PiAction) action).id().id(), is("set_egress_port")); Assert.assertThat(((PiAction) action).parameters().size(), is(1)); Collection<PiActionParam> actionParams = ((PiAction) action).parameters(); PiActionParam actionParam = actionParams.iterator().next(); Assert.assertThat(actionParam.id().id(), is("port")); Assert.assertThat(actionParam.value(), is(copyFrom((byte) 0x1))); Instruction actionGroupIdInstruction = getInstruction("PiActionProfileGroupIdInstruction.json"); Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT)); PiTableAction actionGroupId = ((PiInstruction) actionGroupIdInstruction).action(); Assert.assertThat(actionGroupId.type(), is(PiTableAction.Type.ACTION_PROFILE_GROUP_ID)); Assert.assertThat(((PiActionProfileGroupId) actionGroupId).id(), is(100)); Instruction actionMemberIdInstruction = getInstruction("PiActionProfileMemberIdInstruction.json"); Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT)); PiTableAction actionMemberId = ((PiInstruction) actionMemberIdInstruction).action(); Assert.assertThat(actionMemberId.type(), is(PiTableAction.Type.ACTION_PROFILE_MEMBER_ID)); Assert.assertThat(((PiActionProfileMemberId) actionMemberId).id(), is(100)); }
Example #13
Source File: FabricNextPipelinerTest.java From onos with Apache License 2.0 | 4 votes |
/** * 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() // FIXME: currently next objective doesn't support priority, ignore this .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); }
Example #14
Source File: InstructionJsonMatcher.java From onos with Apache License 2.0 | 4 votes |
/** * 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; }