Search in sources :

Example 61 with PiActionParam

use of org.onosproject.net.pi.runtime.PiActionParam 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)

Example 62 with PiActionParam

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

the class NextObjectiveTranslatorTest method testSimpleOutputWithMacTranslation.

/**
 * 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);
}
Also used : DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 63 with PiActionParam

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

the class NextObjectiveTranslatorTest method setup.

@Before
public void setup() {
    super.doSetup();
    translatorHashed = new NextObjectiveTranslator(DEVICE_ID, capabilitiesHashed);
    translatorSimple = new NextObjectiveTranslator(DEVICE_ID, capabilitiesSimple);
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
    PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_VLAN).withParameter(new PiActionParam(FabricConstants.VLAN_ID, VLAN_100.toShort())).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(piAction).build();
    vlanMetaFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).forTable(FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_MPLS_LABEL).withParameter(new PiActionParam(FabricConstants.LABEL, MPLS_10.toInt())).build();
    treatment = DefaultTrafficTreatment.builder().piTableAction(piAction).build();
    mplsFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).forTable(FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) Before(org.junit.Before)

Example 64 with PiActionParam

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

the class NextObjectiveTranslatorTest method testRouteAndPushNextObjective.

/**
 * Test Route and Push Next Objective (set mac, set double vlan and output port).
 */
@Test
public void testRouteAndPushNextObjective() throws FabricPipelinerException {
    TrafficTreatment routeAndPushTreatment = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(HOST_MAC).setOutput(PORT_1).setVlanId(VLAN_100).pushVlan().setVlanId(VLAN_200).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(routeAndPushTreatment).withType(NextObjective.Type.SIMPLE).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorSimple.translate(nextObjective);
    PiAction piActionRouting = 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();
    PiAction piActionPush = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_DOUBLE_VLAN).withParameter(new PiActionParam(FabricConstants.INNER_VLAN_ID, VLAN_100.toShort())).withParameter(new PiActionParam(FabricConstants.OUTER_VLAN_ID, VLAN_200.toShort())).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build()).build();
    FlowRule expectedFlowRuleRouting = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE).withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionRouting).build()).build();
    FlowRule expectedFlowRuleDoublePush = DefaultFlowRule.builder().withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionPush).build()).forTable(FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRuleDoublePush).addFlowRule(expectedFlowRuleRouting).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 65 with PiActionParam

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

the class IntProgrammableImpl method init.

@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;
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)102 PiAction (org.onosproject.net.pi.runtime.PiAction)90 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)50 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)50 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)39 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)39 Test (org.junit.Test)30 FlowRule (org.onosproject.net.flow.FlowRule)27 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)21 GroupDescription (org.onosproject.net.group.GroupDescription)11 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)10 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)8 NextObjective (org.onosproject.net.flowobjective.NextObjective)8 PortNumber (org.onosproject.net.PortNumber)7 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)7 GroupBucket (org.onosproject.net.group.GroupBucket)7 GroupBuckets (org.onosproject.net.group.GroupBuckets)7 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)7 PiGroupKey (org.onosproject.net.pi.runtime.PiGroupKey)6