org.onosproject.net.pi.model.PiActionId Java Examples
The following examples show how to use
org.onosproject.net.pi.model.PiActionId.
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 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 = "MODIFY ME"; final PiCriterion match = PiCriterion.builder() .matchExact(PiMatchFieldId.of("MODIFY ME"), nexthopMac.toBytes()) .build(); final PiAction action = PiAction.builder() .withId(PiActionId.of("MODIFY ME")) .withParameter(new PiActionParam( PiActionParamId.of("MODIFY ME"), outPort.toLong())) .build(); // ---- END SOLUTION ---- return Utils.buildFlowRule( deviceId, appId, tableId, match, action); }
Example #2
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 #3
Source File: PiActionTest.java From onos with Apache License 2.0 | 6 votes |
/** * Checks the construction of a PiAction object with parameters. */ @Test public void testMethodWithParameters() { PiActionId piActionId = PiActionId.of(MOD_NW_DST); Collection<PiActionParam> runtimeParams = Lists.newArrayList(); PiActionParam piActionParam = new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101)); runtimeParams.add(piActionParam); final PiAction piAction = PiAction.builder().withId(piActionId) .withParameters(runtimeParams) .build(); assertThat(piAction, is(notNullValue())); assertThat(piAction.id(), is(piActionId)); assertThat(piAction.parameters(), is(runtimeParams)); assertThat(piAction.type(), is(PiTableAction.Type.ACTION)); }
Example #4
Source File: P4TableModel.java From onos with Apache License 2.0 | 6 votes |
P4TableModel(PiTableId id, PiTableType tableType, PiActionProfileModel actionProfile, long maxSize, ImmutableMap<PiCounterId, PiCounterModel> counters, ImmutableMap<PiMeterId, PiMeterModel> meters, boolean supportAging, ImmutableMap<PiMatchFieldId, PiMatchFieldModel> matchFields, ImmutableMap<PiActionId, PiActionModel> actions, PiActionModel constDefaultAction, boolean isConstTable) { this.id = id; this.tableType = tableType; this.actionProfile = actionProfile; this.maxSize = maxSize; this.counters = counters; this.meters = meters; this.supportAging = supportAging; this.matchFields = matchFields; this.actions = actions; this.constDefaultAction = constDefaultAction; this.isConstTable = isConstTable; }
Example #5
Source File: P4InfoParser.java From onos with Apache License 2.0 | 6 votes |
private static Map<Integer, PiActionModel> parseActions(P4Info p4info) { final Map<Integer, PiActionModel> actionMap = Maps.newHashMap(); for (Action actionMsg : p4info.getActionsList()) { final ImmutableMap.Builder<PiActionParamId, PiActionParamModel> paramMapBuilder = ImmutableMap.builder(); actionMsg.getParamsList().forEach(paramMsg -> { final PiActionParamId paramId = PiActionParamId.of(paramMsg.getName()); paramMapBuilder.put(paramId, new P4ActionParamModel(PiActionParamId.of(paramMsg.getName()), paramMsg.getBitwidth())); }); actionMap.put( actionMsg.getPreamble().getId(), new P4ActionModel( PiActionId.of(actionMsg.getPreamble().getName()), paramMapBuilder.build())); } return actionMap; }
Example #6
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 #7
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 #8
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 #9
Source File: BasicInterpreterImpl.java From onos with Apache License 2.0 | 5 votes |
private PiAction outputPiAction(OutputInstruction outInstruction, PiActionId piActionId) throws PiInterpreterException { PortNumber port = outInstruction.port(); if (!port.isLogical()) { return PiAction.builder() .withId(piActionId) .withParameter(new PiActionParam(PORT, port.toLong())) .build(); } else if (port.equals(CONTROLLER)) { return PiAction.builder().withId(INGRESS_TABLE0_CONTROL_SEND_TO_CPU).build(); } else { throw new PiInterpreterException(format( "Egress on logical port '%s' not supported", port)); } }
Example #10
Source File: IntProgrammableImpl.java From onos with Apache License 2.0 | 5 votes |
private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId, int matchValue, PiActionId actionId, ApplicationId appId) { PiCriterion instCriterion = PiCriterion.builder() .matchExact(matchFieldId, matchValue) .build(); TrafficSelector instSelector = DefaultTrafficSelector.builder() .matchPi(instCriterion) .build(); PiAction instAction = PiAction.builder() .withId(actionId) .build(); TrafficTreatment instTreatment = DefaultTrafficTreatment.builder() .piTableAction(instAction) .build(); FlowRule instFlowRule = DefaultFlowRule.builder() .withSelector(instSelector) .withTreatment(instTreatment) .withPriority(DEFAULT_PRIORITY) .makePermanent() .forDevice(deviceId) .forTable(tableId) .fromApp(appId) .build(); flowRuleService.applyFlowRules(instFlowRule); }
Example #11
Source File: ForwardingObjectiveTranslator.java From onos with Apache License 2.0 | 5 votes |
private static PiAction setNextIdAction(Integer nextId, PiActionId actionId) { final PiActionParam nextIdParam = new PiActionParam(FabricConstants.NEXT_ID, nextId); return PiAction.builder() .withId(actionId) .withParameter(nextIdParam) .build(); }
Example #12
Source File: MyTunnelApp.java From onos with Apache License 2.0 | 5 votes |
/** * 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); }
Example #13
Source File: PiActionTest.java From onos with Apache License 2.0 | 5 votes |
/** * Checks the construction of a PiAction object with parameter. */ @Test public void testMethodWithParameter() { PiActionId piActionId = PiActionId.of(MOD_NW_DST); PiActionParam piActionParam = new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101)); final PiAction piAction = PiAction.builder().withId(piActionId) .withParameter(piActionParam) .build(); assertThat(piAction, is(notNullValue())); assertThat(piAction.id(), is(piActionId)); assertThat(piAction.type(), is(PiTableAction.Type.ACTION)); }
Example #14
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("<PUT HERE NAME OF NDP REPLY ACTION>")) .withParameter(targetMacParam) .build(); // Table ID. final String tableId = "<PUT HERE NAME OF NDP REPLY TABLE>"; // ---- END SOLUTION ---- // Build flow rule. final FlowRule rule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); return rule; }
Example #15
Source File: L2BridgingComponent.java From ngsdn-tutorial with Apache License 2.0 | 5 votes |
/** * Insert flow rules to forward packets to a given host located at the given * device and port. * <p> * This method will be called at component activation for each host known by * ONOS, and every time a new host-added event is captured by the * InternalHostListener defined below. * * @param host host instance * @param deviceId device where the host is located * @param port port where the host is attached to */ private void learnHost(Host host, DeviceId deviceId, PortNumber port) { log.info("Adding L2 unicast rule on {} for host {} (port {})...", deviceId, host.id(), port); final String tableId = "IngressPipeImpl.l2_exact_table"; // Match exactly on the host MAC address. final MacAddress hostMac = host.mac(); final PiCriterion hostMacCriterion = PiCriterion.builder() .matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"), hostMac.toBytes()) .build(); // Action: set output port final PiAction l2UnicastAction = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.set_egress_port")) .withParameter(new PiActionParam( PiActionParamId.of("port_num"), port.toLong())) .build(); // Forge flow rule. final FlowRule rule = Utils.buildFlowRule( deviceId, appId, tableId, hostMacCriterion, l2UnicastAction); // Insert. flowRuleService.applyFlowRules(rule); }
Example #16
Source File: Ipv6RoutingComponent.java From ngsdn-tutorial with Apache License 2.0 | 5 votes |
/** * Sets up the "My Station" table for the given device using the * myStationMac address found in the config. * <p> * This method will be called at component activation for each device * (switch) known by ONOS, and every time a new device-added event is * captured by the InternalDeviceListener defined below. * * @param deviceId the device ID */ private void setUpMyStationTable(DeviceId deviceId) { log.info("Adding My Station rules to {}...", deviceId); final MacAddress myStationMac = getMyStationMac(deviceId); // HINT: in the p4 program, the My Station table matches on the // *ethernet destination* and there is only one action called // *NoAction*, which is used as an indication of "table hit" in the // control block. final String tableId = "IngressPipeImpl.my_station_table"; final PiCriterion match = PiCriterion.builder() .matchExact( PiMatchFieldId.of("hdr.ethernet.dst_addr"), myStationMac.toBytes()) .build(); // Creates an action which do *NoAction* when hit. final PiTableAction action = PiAction.builder() .withId(PiActionId.of("NoAction")) .build(); final FlowRule myStationRule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); flowRuleService.applyFlowRules(myStationRule); }
Example #17
Source File: Srv6Component.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Insert a SRv6 transit insert policy that will inject an SRv6 header for * packets destined to destIp. * * @param deviceId device ID * @param destIp target IP address for the SRv6 policy * @param prefixLength prefix length for the target IP * @param segmentList list of SRv6 SIDs that make up the path */ public void insertSrv6InsertRule(DeviceId deviceId, Ip6Address destIp, int prefixLength, List<Ip6Address> segmentList) { if (segmentList.size() < 2 || segmentList.size() > 3) { throw new RuntimeException("List of " + segmentList.size() + " segments is not supported"); } // TODO EXERCISE 4 // Fill in the table ID for the SRv6 transit table. // ---- START SOLUTION ---- String tableId = "MODIFY ME"; // ---- END SOLUTION ---- // TODO EXERCISE 4 // Modify match field, action id, and action parameters to match your P4Info. // ---- START SOLUTION ---- PiCriterion match = PiCriterion.builder() .matchLpm(PiMatchFieldId.of("MODIFY ME"), destIp.toOctets(), prefixLength) .build(); List<PiActionParam> actionParams = Lists.newArrayList(); for (int i = 0; i < segmentList.size(); i++) { PiActionParamId paramId = PiActionParamId.of("s" + (i + 1)); PiActionParam param = new PiActionParam(paramId, segmentList.get(i).toOctets()); actionParams.add(param); } PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.srv6_t_insert_" + segmentList.size())) .withParameters(actionParams) .build(); // ---- END SOLUTION ---- final FlowRule rule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); flowRuleService.applyFlowRules(rule); }
Example #18
Source File: Srv6Component.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Populate the My SID table from the network configuration for the * specified device. * * @param deviceId the device Id */ private void setUpMySidTable(DeviceId deviceId) { Ip6Address mySid = getMySid(deviceId); log.info("Adding mySid rule on {} (sid {})...", deviceId, mySid); // TODO EXERCISE 4 // Fill in the table ID for the SRv6 my segment identifier table // ---- START SOLUTION ---- String tableId = "MODIFY ME"; // ---- END SOLUTION ---- // TODO EXERCISE 4 // Modify the field and action id to match your P4Info // ---- START SOLUTION ---- PiCriterion match = PiCriterion.builder() .matchLpm( PiMatchFieldId.of("MODIFY ME"), mySid.toOctets(), 128) .build(); PiTableAction action = PiAction.builder() .withId(PiActionId.of("MODIFY ME")) .build(); // ---- END SOLUTION ---- FlowRule myStationRule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); flowRuleService.applyFlowRules(myStationRule); }
Example #19
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 #20
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Creates an ONOS SELECT group for the routing table to provide ECMP * forwarding for the given collection of next hop MAC addresses. ONOS * SELECT groups are equivalent to P4Runtime action selector groups. * <p> * This method will be called by the routing policy methods below to insert * groups in the L3 table * * @param nextHopMacs the collection of mac addresses of next hops * @param deviceId the device where the group will be installed * @return a SELECT group */ private GroupDescription createNextHopGroup(int groupId, Collection<MacAddress> nextHopMacs, DeviceId deviceId) { String actionProfileId = "IngressPipeImpl.ecmp_selector"; final List<PiAction> actions = Lists.newArrayList(); // Build one "set next hop" action for each next hop // 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"; for (MacAddress nextHopMac : nextHopMacs) { final PiAction action = PiAction.builder() .withId(PiActionId.of("MODIFY ME")) .withParameter(new PiActionParam( // Action param name. PiActionParamId.of("MODIFY ME"), // Action param value. nextHopMac.toBytes())) .build(); actions.add(action); } // ---- END SOLUTION ---- return Utils.buildSelectGroup( deviceId, tableId, actionProfileId, groupId, actions, appId); }
Example #21
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Sets up the "My Station" table for the given device using the * myStationMac address found in the config. * <p> * This method will be called at component activation for each device * (switch) known by ONOS, and every time a new device-added event is * captured by the InternalDeviceListener defined below. * * @param deviceId the device ID */ private void setUpMyStationTable(DeviceId deviceId) { log.info("Adding My Station rules to {}...", deviceId); final MacAddress myStationMac = getMyStationMac(deviceId); // HINT: in our solution, the My Station table matches on the *ethernet // destination* and there is only one action called *NoAction*, which is // used as an indication of "table hit" in the control block. // 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() .matchExact( PiMatchFieldId.of("MODIFY ME"), myStationMac.toBytes()) .build(); // Creates an action which do *NoAction* when hit. final PiTableAction action = PiAction.builder() .withId(PiActionId.of("MODIFY ME")) .build(); // ---- END SOLUTION ---- final FlowRule myStationRule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); flowRuleService.applyFlowRules(myStationRule); }
Example #22
Source File: L2BridgingComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Insert flow rules to forward packets to a given host located at the given * device and port. * <p> * This method will be called at component activation for each host known by * ONOS, and every time a new host-added event is captured by the * InternalHostListener defined below. * * @param host host instance * @param deviceId device where the host is located * @param port port where the host is attached to */ private void learnHost(Host host, DeviceId deviceId, PortNumber port) { log.info("Adding L2 unicast rule on {} for host {} (port {})...", deviceId, host.id(), port); // TODO EXERCISE 2 // 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"; // Match exactly on the host MAC address. final MacAddress hostMac = host.mac(); final PiCriterion hostMacCriterion = PiCriterion.builder() .matchExact(PiMatchFieldId.of("MODIFY ME"), hostMac.toBytes()) .build(); // Action: set output port final PiAction l2UnicastAction = PiAction.builder() .withId(PiActionId.of("MODIFY ME")) .withParameter(new PiActionParam( PiActionParamId.of("MODIFY ME"), port.toLong())) .build(); // ---- END SOLUTION ---- // Forge flow rule. final FlowRule rule = Utils.buildFlowRule( deviceId, appId, tableId, hostMacCriterion, l2UnicastAction); // Insert. flowRuleService.applyFlowRules(rule); }
Example #23
Source File: NdpReplyComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId, MacAddress deviceMac, Ip6Address targetIp) { PiCriterion match = PiCriterion.builder() .matchExact(PiMatchFieldId.of("hdr.ndp.target_addr"), targetIp.toOctets()) .build(); PiActionParam paramRouterMac = new PiActionParam( PiActionParamId.of("target_mac"), deviceMac.toBytes()); PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na")) .withParameter(paramRouterMac) .build(); TrafficSelector selector = DefaultTrafficSelector.builder() .matchPi(match) .build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder() .piTableAction(action) .build(); return DefaultFlowRule.builder() .forDevice(deviceId) .forTable(PiTableId.of("IngressPipeImpl.ndp_reply_table")) .fromApp(appId) .makePermanent() .withSelector(selector) .withTreatment(treatment) .withPriority(DEFAULT_FLOW_RULE_PRIORITY) .build(); }
Example #24
Source File: PiActionIdTest.java From onos with Apache License 2.0 | 5 votes |
/** * Checks the construction of a PiActionId object. */ @Test public void testConstruction() { final PiActionId actionId = PiActionId.of(DEC_TTL); assertThat(actionId, is(notNullValue())); assertThat(actionId.id(), is(DEC_TTL)); }
Example #25
Source File: Srv6Component.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Insert a SRv6 transit insert policy that will inject an SRv6 header for * packets destined to destIp. * * @param deviceId device ID * @param destIp target IP address for the SRv6 policy * @param prefixLength prefix length for the target IP * @param segmentList list of SRv6 SIDs that make up the path */ public void insertSrv6InsertRule(DeviceId deviceId, Ip6Address destIp, int prefixLength, List<Ip6Address> segmentList) { if (segmentList.size() < 2 || segmentList.size() > 3) { throw new RuntimeException("List of " + segmentList.size() + " segments is not supported"); } // TODO EXERCISE 4 // Fill in the table ID for the SRv6 transit table. // ---- START SOLUTION ---- String tableId = "IngressPipeImpl.srv6_transit"; // ---- END SOLUTION ---- // TODO EXERCISE 4 // Modify match field, action id, and action parameter to match your P4Info. // ---- START SOLUTION ---- PiCriterion match = PiCriterion.builder() .matchLpm(PiMatchFieldId.of("hdr.ipv6.dst_addr"), destIp.toOctets(), prefixLength) .build(); List<PiActionParam> actionParams = Lists.newArrayList(); for (int i = 0; i < segmentList.size(); i++) { PiActionParamId paramId = PiActionParamId.of("s" + (i + 1)); PiActionParam param = new PiActionParam(paramId, segmentList.get(i).toOctets()); actionParams.add(param); } PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.srv6_t_insert_" + segmentList.size())) .withParameters(actionParams) .build(); // ---- END SOLUTION ---- final FlowRule rule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); flowRuleService.applyFlowRules(rule); }
Example #26
Source File: Srv6Component.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Populate the My SID table from the network configuration for the * specified device. * * @param deviceId the device Id */ private void setUpMySidTable(DeviceId deviceId) { Ip6Address mySid = getMySid(deviceId); log.info("Adding mySid rule on {} (sid {})...", deviceId, mySid); // TODO EXERCISE 4 // Fill in the table ID for the SRv6 my segment identifier table // ---- START SOLUTION ---- String tableId = "IngressPipeImpl.srv6_my_sid"; // ---- END SOLUTION ---- // TODO EXERCISE 4 // Modify the field and action id to match your P4Info // ---- START SOLUTION ---- PiCriterion match = PiCriterion.builder() .matchLpm( PiMatchFieldId.of("hdr.ipv6.dst_addr"), mySid.toOctets(), 128) .build(); PiTableAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.srv6_end")) .build(); // ---- END SOLUTION ---- FlowRule myStationRule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); flowRuleService.applyFlowRules(myStationRule); }
Example #27
Source File: Ipv6RoutingComponent.java From ngsdn-tutorial with Apache License 2.0 | 5 votes |
/** * Creates an ONOS SELECT group for the routing table to provide ECMP * forwarding for the given collection of next hop MAC addresses. ONOS * SELECT groups are equivalent to P4Runtime action selector groups. * <p> * This method will be called by the routing policy methods below to insert * groups in the L3 table * * @param nextHopMacs the collection of mac addresses of next hops * @param deviceId the device where the group will be installed * @return a SELECT group */ private GroupDescription createNextHopGroup(int groupId, Collection<MacAddress> nextHopMacs, DeviceId deviceId) { String actionProfileId = "IngressPipeImpl.ecmp_selector"; final List<PiAction> actions = Lists.newArrayList(); // Build one "set next hop" action for each next hop final String tableId = "IngressPipeImpl.routing_v6_table"; for (MacAddress nextHopMac : nextHopMacs) { final PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.set_next_hop")) .withParameter(new PiActionParam( // Action param name. PiActionParamId.of("dmac"), // Action param value. nextHopMac.toBytes())) .build(); actions.add(action); } return Utils.buildSelectGroup( deviceId, tableId, actionProfileId, groupId, actions, appId); }
Example #28
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Creates an ONOS SELECT group for the routing table to provide ECMP * forwarding for the given collection of next hop MAC addresses. ONOS * SELECT groups are equivalent to P4Runtime action selector groups. * <p> * This method will be called by the routing policy methods below to insert * groups in the L3 table * * @param nextHopMacs the collection of mac addresses of next hops * @param deviceId the device where the group will be installed * @return a SELECT group */ private GroupDescription createNextHopGroup(int groupId, Collection<MacAddress> nextHopMacs, DeviceId deviceId) { String actionProfileId = "IngressPipeImpl.ecmp_selector"; final List<PiAction> actions = Lists.newArrayList(); // Build one "set next hop" action for each next hop // 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"; for (MacAddress nextHopMac : nextHopMacs) { final PiAction action = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.set_l2_next_hop")) .withParameter(new PiActionParam( // Action param name. PiActionParamId.of("dmac"), // Action param value. nextHopMac.toBytes())) .build(); actions.add(action); } // ---- END SOLUTION ---- return Utils.buildSelectGroup( deviceId, tableId, actionProfileId, groupId, actions, appId); }
Example #29
Source File: Ipv6RoutingComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Sets up the "My Station" table for the given device using the * myStationMac address found in the config. * <p> * This method will be called at component activation for each device * (switch) known by ONOS, and every time a new device-added event is * captured by the InternalDeviceListener defined below. * * @param deviceId the device ID */ private void setUpMyStationTable(DeviceId deviceId) { log.info("Adding My Station rules to {}...", deviceId); final MacAddress myStationMac = getMyStationMac(deviceId); // HINT: in our solution, the My Station table matches on the *ethernet // destination* and there is only one action called *NoAction*, which is // used as an indication of "table hit" in the control block. // 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_my_station"; final PiCriterion match = PiCriterion.builder() .matchExact( PiMatchFieldId.of("hdr.ethernet.dst_addr"), myStationMac.toBytes()) .build(); // Creates an action which do *NoAction* when hit. final PiTableAction action = PiAction.builder() .withId(PiActionId.of("NoAction")) .build(); // ---- END SOLUTION ---- final FlowRule myStationRule = Utils.buildFlowRule( deviceId, appId, tableId, match, action); flowRuleService.applyFlowRules(myStationRule); }
Example #30
Source File: L2BridgingComponent.java From onos-p4-tutorial with Apache License 2.0 | 5 votes |
/** * Insert flow rules to forward packets to a given host located at the given * device and port. * <p> * This method will be called at component activation for each host known by * ONOS, and every time a new host-added event is captured by the * InternalHostListener defined below. * * @param host host instance * @param deviceId device where the host is located * @param port port where the host is attached to */ private void learnHost(Host host, DeviceId deviceId, PortNumber port) { log.info("Adding L2 unicast rule on {} for host {} (port {})...", deviceId, host.id(), port); // TODO EXERCISE 2 // 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"; // Match exactly on the host MAC address. final MacAddress hostMac = host.mac(); final PiCriterion hostMacCriterion = PiCriterion.builder() .matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"), hostMac.toBytes()) .build(); // Action: set output port final PiAction l2UnicastAction = PiAction.builder() .withId(PiActionId.of("IngressPipeImpl.set_output_port")) .withParameter(new PiActionParam( PiActionParamId.of("port_num"), port.toLong())) .build(); // Forge flow rule. final FlowRule rule = Utils.buildFlowRule( deviceId, appId, tableId, hostMacCriterion, l2UnicastAction); // ---- END SOLUTION ---- // Insert. flowRuleService.applyFlowRules(rule); }