org.onosproject.net.pi.runtime.PiAction Java Examples
The following examples show how to use
org.onosproject.net.pi.runtime.PiAction.
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: ActionCodec.java From onos with Apache License 2.0 | 6 votes |
@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()); 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(); }
Example #2
Source File: FabricInterpreterTest.java From onos with Apache License 2.0 | 6 votes |
/** * Map treatment for hashed table to routing v4 action. */ @Test public void testNextTreatmentHashedRoutingMpls() throws Exception { TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setEthSrc(SRC_MAC) .setEthDst(DST_MAC) .setOutput(PORT_1) .pushMpls() .setMpls(MPLS_10) .build(); PiAction mappedAction = interpreter.mapTreatment( treatment, FabricConstants.FABRIC_INGRESS_NEXT_HASHED); PiActionParam ethSrcParam = new PiActionParam(FabricConstants.SMAC, SRC_MAC.toBytes()); PiActionParam ethDstParam = new PiActionParam(FabricConstants.DMAC, DST_MAC.toBytes()); PiActionParam portParam = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong()); PiActionParam mplsParam = new PiActionParam(FabricConstants.LABEL, MPLS_10.toInt()); PiAction expectedAction = PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_NEXT_MPLS_ROUTING_HASHED) .withParameters(ImmutableList.of(ethSrcParam, ethDstParam, portParam, mplsParam)) .build(); assertEquals(expectedAction, mappedAction); }
Example #3
Source File: FabricNextPipelinerTest.java From onos with Apache License 2.0 | 6 votes |
/** * Test program set mac, set vlan, and output rule for Simple table. */ @Test public void testSimpleOutputWithVlanAndMacTranslation() throws FabricPipelinerException { TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setEthSrc(ROUTER_MAC) .setEthDst(HOST_MAC) .setVlanId(VLAN_100) .setOutput(PORT_1) .build(); PiAction piAction = 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(); testSimple(treatment, piAction); }
Example #4
Source File: MyTunnelApp.java From onos with Apache License 2.0 | 6 votes |
/** * Inserts a flow rule in the system that using a PI criterion and action. * * @param switchId switch ID * @param tableId table ID * @param piCriterion PI criterion * @param piAction PI action */ private void insertPiFlowRule(DeviceId switchId, PiTableId tableId, PiCriterion piCriterion, PiAction piAction) { FlowRule rule = DefaultFlowRule.builder() .forDevice(switchId) .forTable(tableId) .fromApp(appId) .withPriority(FLOW_RULE_PRIORITY) .makePermanent() .withSelector(DefaultTrafficSelector.builder() .matchPi(piCriterion).build()) .withTreatment(DefaultTrafficTreatment.builder() .piTableAction(piAction).build()) .build(); flowRuleService.applyFlowRules(rule); }
Example #5
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 6 votes |
/** * Creates a flow rule for the L2 table mapping the given next hop MAC to * the given output port. * <p> * This is called by the routing policy methods below to establish L2-based * forwarding inside the fabric, e.g., when deviceId is a leaf switch and * nextHopMac is the one of a spine switch. * * @param deviceId the device * @param nexthopMac the next hop (destination) mac * @param outPort the output port */ private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac, PortNumber outPort) { // 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.l2_exact_table"; final PiCriterion match = PiCriterion.builder() .matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"), nexthopMac.toBytes()) .build(); final PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.set_output_port")) .withParameter(new PiActionParam( PiActionParamId.of("port_num"), outPort.toLong())) .build(); // ---- END SOLUTION ---- return Utils.buildFlowRule( deviceId, appId, tableId, match, action); }
Example #6
Source File: FabricBngProgrammable.java From onos with Apache License 2.0 | 6 votes |
/** * Build the flow rule for the table t_pppoe_cp of the ingress upstream. */ private FlowRule buildTPppoeCpFlowRule(PiCriterion criterion, ApplicationId appId) { TrafficSelector trafficSelector = DefaultTrafficSelector.builder() .matchPi(criterion) .build(); TrafficTreatment instTreatment = DefaultTrafficTreatment.builder() .piTableAction(PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_BNG_INGRESS_UPSTREAM_PUNT_TO_CPU) .build() ) .build(); return buildFlowRule(trafficSelector, instTreatment, FabricConstants.FABRIC_INGRESS_BNG_INGRESS_UPSTREAM_T_PPPOE_CP, appId); }
Example #7
Source File: AbstractObjectiveTranslator.java From onos with Apache License 2.0 | 6 votes |
TrafficTreatment mapTreatmentToPiIfNeeded(TrafficTreatment treatment, PiTableId tableId) throws FabricPipelinerException { if (isTreatmentPi(treatment)) { return treatment; } final PiAction piAction; try { piAction = interpreter.mapTreatment(treatment, tableId); } catch (PiPipelineInterpreter.PiInterpreterException ex) { throw new FabricPipelinerException( format("Unable to map treatment for table '%s': %s", tableId, ex.getMessage()), ObjectiveError.UNSUPPORTED); } return DefaultTrafficTreatment.builder() .piTableAction(piAction) .build(); }
Example #8
Source File: FabricInterpreterTest.java From onos with Apache License 2.0 | 6 votes |
/** * Map treatment to set_vlan_output action. */ @Test public void testNextTreatment3() throws Exception { TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setVlanId(VLAN_100) .build(); PiAction mappedAction = interpreter.mapTreatment( treatment, FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN); PiActionParam vlanParam = new PiActionParam( FabricConstants.VLAN_ID, VLAN_100.toShort()); PiAction expectedAction = PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN) .withParameter(vlanParam) .build(); assertEquals(expectedAction, mappedAction); }
Example #9
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 #10
Source File: FabricNextPipelinerTest.java From onos with Apache License 2.0 | 6 votes |
/** * Test program set mac and output rule for Simple table. */ @Test public void testSimpleOutputWithMacTranslation() throws FabricPipelinerException { TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setEthSrc(ROUTER_MAC) .setEthDst(HOST_MAC) .setOutput(PORT_1) .build(); PiAction piAction = 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(); testSimple(treatment, piAction); }
Example #11
Source File: Ipv6RoutingComponent.java From ngsdn-tutorial with Apache License 2.0 | 6 votes |
/** * Creates a flow rule for the L2 table mapping the given next hop MAC to * the given output port. * <p> * This is called by the routing policy methods below to establish L2-based * forwarding inside the fabric, e.g., when deviceId is a leaf switch and * nextHopMac is the one of a spine switch. * * @param deviceId the device * @param nexthopMac the next hop (destination) mac * @param outPort the output port */ private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac, PortNumber outPort) { final String tableId = "IngressPipeImpl.l2_exact_table"; final PiCriterion match = PiCriterion.builder() .matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"), nexthopMac.toBytes()) .build(); final PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.set_egress_port")) .withParameter(new PiActionParam( PiActionParamId.of("port_num"), outPort.toLong())) .build(); return Utils.buildFlowRule( deviceId, appId, tableId, match, action); }
Example #12
Source File: ActionCodec.java From onos with Apache License 2.0 | 6 votes |
@Override protected PiAction decode( P4RuntimeOuterClass.Action message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { final P4InfoBrowser.EntityBrowser<P4InfoOuterClass.Action.Param> paramInfo = browser.actionParams(message.getActionId()); final String actionName = browser.actions() .getById(message.getActionId()) .getPreamble().getName(); final PiAction.Builder builder = PiAction.builder() .withId(PiActionId.of(actionName)); for (P4RuntimeOuterClass.Action.Param p : message.getParamsList()) { final String paramName = paramInfo.getById(p.getParamId()).getName(); final ImmutableByteSequence value = ImmutableByteSequence.copyFrom( p.getValue().toByteArray()); builder.withParameter(new PiActionParam(PiActionParamId.of(paramName), value)); } return builder.build(); }
Example #13
Source File: FabricInterpreter.java From onos with Apache License 2.0 | 6 votes |
@Override public PiAction mapTreatment(TrafficTreatment treatment, PiTableId piTableId) throws PiInterpreterException { if (FILTERING_CTRL_TBLS.contains(piTableId)) { return treatmentInterpreter.mapFilteringTreatment(treatment, piTableId); } else if (FORWARDING_CTRL_TBLS.contains(piTableId)) { return treatmentInterpreter.mapForwardingTreatment(treatment, piTableId); } else if (ACL_CTRL_TBLS.contains(piTableId)) { return treatmentInterpreter.mapAclTreatment(treatment, piTableId); } else if (NEXT_CTRL_TBLS.contains(piTableId)) { return treatmentInterpreter.mapNextTreatment(treatment, piTableId); } else if (E_NEXT_CTRL_TBLS.contains(piTableId)) { return treatmentInterpreter.mapEgressNextTreatment(treatment, piTableId); } else { throw new PiInterpreterException(format( "Treatment mapping not supported for table '%s'", piTableId)); } }
Example #14
Source File: Utils.java From onos-p4-tutorial with Apache License 2.0 | 6 votes |
public static GroupDescription buildSelectGroup(DeviceId deviceId, String tableId, String actionProfileId, int groupId, Collection<PiAction> actions, ApplicationId appId) { final GroupKey groupKey = new PiGroupKey( PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId); final List<GroupBucket> buckets = actions.stream() .map(action -> DefaultTrafficTreatment.builder() .piTableAction(action).build()) .map(DefaultGroupBucket::createSelectGroupBucket) .collect(Collectors.toList()); return new DefaultGroupDescription( deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), groupKey, groupId, appId); }
Example #15
Source File: FabricTreatmentInterpreter.java From onos with Apache License 2.0 | 6 votes |
static PiAction mapFilteringTreatment(TrafficTreatment treatment, PiTableId tableId) throws PiInterpreterException { if (!tableId.equals(FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN)) { // Mapping for other tables of the filtering block must be handled // in the pipeliner. tableException(tableId); } // VLAN_POP action is equivalent to the permit action (VLANs pop is done anyway) if (isNoAction(treatment) || isFilteringPopAction(treatment)) { // Permit action if table is ingress_port_vlan; return nop(tableId); } final ModVlanIdInstruction setVlanInst = (ModVlanIdInstruction) l2InstructionOrFail( treatment, VLAN_ID, tableId); return PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN) .withParameter(new PiActionParam( FabricConstants.VLAN_ID, setVlanInst.vlanId().toShort())) .build(); }
Example #16
Source File: Utils.java From ngsdn-tutorial with Apache License 2.0 | 6 votes |
public static GroupDescription buildSelectGroup(DeviceId deviceId, String tableId, String actionProfileId, int groupId, Collection<PiAction> actions, ApplicationId appId) { final GroupKey groupKey = new PiGroupKey( PiTableId.of(tableId), PiActionProfileId.of(actionProfileId), groupId); final List<GroupBucket> buckets = actions.stream() .map(action -> DefaultTrafficTreatment.builder() .piTableAction(action).build()) .map(DefaultGroupBucket::createSelectGroupBucket) .collect(Collectors.toList()); return new DefaultGroupDescription( deviceId, GroupDescription.Type.SELECT, new GroupBuckets(buckets), groupKey, groupId, appId); }
Example #17
Source File: FabricTreatmentInterpreter.java From onos with Apache License 2.0 | 5 votes |
static PiAction mapForwardingTreatment(TrafficTreatment treatment, PiTableId tableId) throws PiInterpreterException { if (isNoAction(treatment)) { return nop(tableId); } treatmentException( tableId, treatment, "supports mapping only for empty/no-action treatments"); return null; }
Example #18
Source File: FabricTreatmentInterpreter.java From onos with Apache License 2.0 | 5 votes |
PiAction mapNextTreatment(TrafficTreatment treatment, PiTableId tableId) throws PiInterpreterException { if (tableId == FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN) { return mapNextVlanTreatment(treatment, tableId); } else if (tableId == FabricConstants.FABRIC_INGRESS_NEXT_HASHED) { return mapNextHashedOrSimpleTreatment(treatment, tableId, false); } else if (tableId == FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE) { return mapNextHashedOrSimpleTreatment(treatment, tableId, true); } else if (tableId == FabricConstants.FABRIC_INGRESS_NEXT_XCONNECT) { return mapNextXconnect(treatment, tableId); } throw new PiInterpreterException(format( "Treatment mapping not supported for table '%s'", tableId)); }
Example #19
Source File: FabricTreatmentInterpreter.java From onos with Apache License 2.0 | 5 votes |
private static PiAction mapNextXconnect( TrafficTreatment treatment, PiTableId tableId) throws PiInterpreterException { final PortNumber outPort = ((OutputInstruction) instructionOrFail( treatment, OUTPUT, tableId)).port(); return PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_XCONNECT) .withParameter(new PiActionParam( FabricConstants.PORT_NUM, outPort.toLong())) .build(); }
Example #20
Source File: NdpReplyComponent.java From ngsdn-tutorial with Apache License 2.0 | 5 votes |
/** * Build a flow rule for the NDP reply table on the given device, for the * given target IPv6 address and MAC address. * * @param deviceId device ID where to install the flow rules * @param targetIpv6Address target IPv6 address * @param targetMac target MAC address * @return flow rule object */ private FlowRule buildNdpReplyFlowRule(DeviceId deviceId, Ip6Address targetIpv6Address, MacAddress targetMac) { // ** TODO EXERCISE 4 // Modify P4Runtime entity names to match content of P4Info file (look // for the fully qualified name of tables, match fields, and actions. // ---- START SOLUTION ---- // Build match. final PiCriterion match = PiCriterion.builder() .matchExact(PiMatchFieldId.of("hdr.ndp.target_ipv6_addr"), targetIpv6Address.toOctets()) .build(); // Build action. final PiActionParam targetMacParam = new PiActionParam( PiActionParamId.of("target_mac"), targetMac.toBytes()); final PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na")) .withParameter(targetMacParam) .build(); // Table ID. final String tableId = "IngressPipeImpl.ndp_reply_table"; // ---- END SOLUTION ---- // Build flow rule. final FlowRule rule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); return rule; }
Example #21
Source File: P4RuntimeGroupTest.java From onos with Apache License 2.0 | 5 votes |
private static PiActionProfileMember outputMember(short portNum) { PiActionParam param = new PiActionParam(PORT_PARAM_ID, ImmutableByteSequence.copyFrom(portNum)); PiAction piAction = PiAction.builder() .withId(EGRESS_PORT_ACTION_ID) .withParameter(param).build(); return PiActionProfileMember.builder() .forActionProfile(ACT_PROF_ID) .withAction(piAction) .withId(PiActionProfileMemberId.of(BASE_MEM_ID + portNum)) .build(); }
Example #22
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 #23
Source File: FabricTreatmentInterpreter.java From onos with Apache License 2.0 | 5 votes |
static PiAction mapAclTreatment(TrafficTreatment treatment, PiTableId tableId) throws PiInterpreterException { if (isNoAction(treatment)) { return nop(tableId); } treatmentException( tableId, treatment, "unsupported treatment"); // This function will never return null return null; }
Example #24
Source File: FabricIntProgrammable.java From onos with Apache License 2.0 | 5 votes |
@Override public boolean setSinkPort(PortNumber port) { if (!setupBehaviour()) { return false; } PiCriterion egressCriterion = PiCriterion.builder() .matchExact(FabricConstants.HDR_EG_PORT, port.toLong()) .build(); TrafficSelector sinkSelector = DefaultTrafficSelector.builder() .matchPi(egressCriterion) .build(); PiAction setSinkAct = PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_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(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK) .build(); flowRuleService.applyFlowRules(sinkFlowRule); return true; }
Example #25
Source File: FabricInterpreterTest.java From onos with Apache License 2.0 | 5 votes |
/** * Map treatment to permit action. */ @Test public void testFilteringTreatmentPermit() throws Exception { TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); PiAction mappedAction = interpreter.mapTreatment(treatment, FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN); PiAction expectedAction = PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT) .build(); assertEquals(expectedAction, mappedAction); }
Example #26
Source File: FabricInterpreterTest.java From onos with Apache License 2.0 | 5 votes |
/** * Map empty treatment for routing v4 table. */ @Test public void testRoutingV4TreatmentEmpty() throws Exception { TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); PiAction mappedAction = interpreter.mapTreatment( treatment, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4); PiAction expectedAction = PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_FORWARDING_NOP_ROUTING_V4) .build(); assertEquals(expectedAction, mappedAction); }
Example #27
Source File: FabricInterpreterTest.java From onos with Apache License 2.0 | 5 votes |
/** * Map empty treatment for ACL table. */ @Test public void testAclTreatmentEmpty() throws Exception { TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); PiAction mappedAction = interpreter.mapTreatment( treatment, FabricConstants.FABRIC_INGRESS_ACL_ACL); PiAction expectedAction = PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_ACL_NOP_ACL) .build(); assertEquals(expectedAction, mappedAction); }
Example #28
Source File: IntProgrammableImpl.java From onos with Apache License 2.0 | 5 votes |
@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; }
Example #29
Source File: PiFlowRuleTranslatorImpl.java From onos with Apache License 2.0 | 5 votes |
private static PiTableAction checkPiAction(PiAction piAction, PiTableModel table) throws PiTranslationException { // Table supports this action? PiActionModel actionModel = table.action(piAction.id()).orElseThrow( () -> new PiTranslationException(format("Not such action '%s' for table '%s'", piAction.id(), table.id()))); // Is the number of runtime parameters correct? if (actionModel.params().size() != piAction.parameters().size()) { throw new PiTranslationException(format( "Wrong number of runtime parameters for action '%s', expected %d but found %d", actionModel.id(), actionModel.params().size(), piAction.parameters().size())); } // Forge a new action instance with well-sized parameters. // The same comment as in typeCheckFieldMatch() about duplicating field match instances applies here. PiAction.Builder newActionBuilder = PiAction.builder().withId(piAction.id()); for (PiActionParam param : piAction.parameters()) { PiActionParamModel paramModel = actionModel.param(param.id()) .orElseThrow(() -> new PiTranslationException(format( "Not such parameter '%s' for action '%s'", param.id(), actionModel))); try { newActionBuilder.withParameter(new PiActionParam(param.id(), param.value().fit(paramModel.bitWidth()))); } catch (ByteSequenceTrimException e) { throw new PiTranslationException(format( "Size mismatch for parameter '%s' of action '%s': %s", param.id(), piAction.id(), e.getMessage())); } } return newActionBuilder.build(); }
Example #30
Source File: NextObjectiveTranslator.java From onos with Apache License 2.0 | 5 votes |
private void multicastNext(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException { // Create ALL group that will be translated to a PRE multicast entry. final int groupId = allGroup(obj, resultBuilder); if (isGroupModifyOp(obj)) { // No changes to flow rules. return; } final TrafficSelector selector = nextIdSelector(obj.id()); final PiActionParam groupIdParam = new PiActionParam( FabricConstants.GROUP_ID, groupId); final PiAction setMcGroupAction = PiAction.builder() .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_MCAST_GROUP_ID) .withParameter(groupIdParam) .build(); final TrafficTreatment treatment = DefaultTrafficTreatment.builder() .piTableAction(setMcGroupAction) .build(); resultBuilder.addFlowRule(flowRule( obj, FabricConstants.FABRIC_INGRESS_NEXT_MULTICAST, selector, treatment)); }