use of org.onosproject.net.flow.criteria.PiCriterion 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);
}
use of org.onosproject.net.flow.criteria.PiCriterion 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();
}
use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class IntProgrammableImpl method setSinkPort.
@Override
public boolean setSinkPort(PortNumber port) {
if (!setupBehaviour()) {
return false;
}
// process_set_source_sink.tb_set_sink
PiCriterion egressCriterion = PiCriterion.builder().matchExact(IntConstants.HDR_STANDARD_METADATA_EGRESS_SPEC, port.toLong()).build();
TrafficSelector sinkSelector = DefaultTrafficSelector.builder().matchPi(egressCriterion).build();
PiAction setSinkAct = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_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(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SINK).build();
flowRuleService.applyFlowRules(sinkFlowRule);
return true;
}
use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class IntProgrammableImpl method setSourcePort.
@Override
public boolean setSourcePort(PortNumber port) {
if (!setupBehaviour()) {
return false;
}
// process_int_source_sink.tb_set_source for each host-facing port
PiCriterion ingressCriterion = PiCriterion.builder().matchExact(IntConstants.HDR_STANDARD_METADATA_INGRESS_PORT, port.toLong()).build();
TrafficSelector srcSelector = DefaultTrafficSelector.builder().matchPi(ingressCriterion).build();
PiAction setSourceAct = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_INT_SET_SOURCE).build();
TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder().piTableAction(setSourceAct).build();
FlowRule srcFlowRule = DefaultFlowRule.builder().withSelector(srcSelector).withTreatment(srcTreatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SOURCE).build();
flowRuleService.applyFlowRules(srcFlowRule);
return true;
}
use of org.onosproject.net.flow.criteria.PiCriterion in project onos by opennetworkinglab.
the class MyTunnelApp method insertTunnelIngressRule.
/**
* 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);
}
Aggregations