use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class IntProgrammableImpl method buildWatchlistEntry.
private FlowRule buildWatchlistEntry(IntObjective obj) {
int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
PiActionParam hopMetaLenParam = new PiActionParam(IntConstants.HOP_METADATA_LEN, ImmutableByteSequence.copyFrom(Integer.bitCount(instructionBitmap)));
PiActionParam hopCntParam = new PiActionParam(IntConstants.REMAINING_HOP_CNT, ImmutableByteSequence.copyFrom(MAXHOP));
PiActionParam inst0003Param = new PiActionParam(IntConstants.INS_MASK0003, ImmutableByteSequence.copyFrom((instructionBitmap >> 12) & 0xF));
PiActionParam inst0407Param = new PiActionParam(IntConstants.INS_MASK0407, ImmutableByteSequence.copyFrom((instructionBitmap >> 8) & 0xF));
PiAction intSourceAction = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_INT_SOURCE_DSCP).withParameter(hopMetaLenParam).withParameter(hopCntParam).withParameter(inst0003Param).withParameter(inst0407Param).build();
TrafficTreatment instTreatment = DefaultTrafficTreatment.builder().piTableAction(intSourceAction).build();
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
for (Criterion criterion : obj.selector().criteria()) {
switch(criterion.type()) {
case IPV4_SRC:
sBuilder.matchIPSrc(((IPCriterion) criterion).ip());
break;
case IPV4_DST:
sBuilder.matchIPDst(((IPCriterion) criterion).ip());
break;
case TCP_SRC:
sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_SRC_PORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
break;
case UDP_SRC:
sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_SRC_PORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
break;
case TCP_DST:
sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_DST_PORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
break;
case UDP_DST:
sBuilder.matchPi(PiCriterion.builder().matchTernary(IntConstants.HDR_LOCAL_METADATA_L4_DST_PORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
break;
default:
log.warn("Unsupported criterion type: {}", criterion.type());
}
}
return DefaultFlowRule.builder().forDevice(this.data().deviceId()).withSelector(sBuilder.build()).withTreatment(instTreatment).withPriority(DEFAULT_PRIORITY).forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_TB_INT_SOURCE).fromApp(appId).withIdleTimeout(IDLE_TIMEOUT).build();
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class FabricIntProgrammable method init.
@Override
public boolean init() {
if (!setupBehaviour()) {
return false;
}
// FIXME: create config class for INT to allow specifying arbitrary
// switch IDs. The one for the GeneralDeviceProvider was temporary and
// now has been removed. For now we use the chassis ID.
// final GeneralProviderDeviceConfig cfg = cfgService.getConfig(
// deviceId, GeneralProviderDeviceConfig.class);
// if (cfg == null) {
// log.warn("Missing GeneralProviderDevice config for {}", deviceId);
// return false;
// }
// final String switchId = cfg.protocolsInfo().containsKey("int") ?
// cfg.protocolsInfo().get("int").configValues().get("switchId")
// : null;
// if (switchId == null || switchId.isEmpty()) {
// log.warn("Missing INT device config for {}", deviceId);
// return false;
// }
PiActionParam transitIdParam = new PiActionParam(FabricConstants.SWITCH_ID, copyFrom(handler().get(DeviceService.class).getDevice(deviceId).chassisId().id()));
PiAction transitAction = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INIT_METADATA).withParameter(transitIdParam).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(transitAction).build();
TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(FabricConstants.HDR_INT_IS_VALID, (byte) 0x01).build()).build();
FlowRule transitFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT).build();
flowRuleService.applyFlowRules(transitFlowRule);
return true;
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class FabricIntProgrammable method setSourcePort.
@Override
public boolean setSourcePort(PortNumber port) {
if (!setupBehaviour()) {
return false;
}
PiCriterion ingressCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_IG_PORT, port.toLong()).build();
TrafficSelector srcSelector = DefaultTrafficSelector.builder().matchPi(ingressCriterion).build();
PiAction setSourceAct = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_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(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE).build();
flowRuleService.applyFlowRules(srcFlowRule);
return true;
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class NextObjectiveTranslator method multicastNext.
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));
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class FabricInterpreterTest method testNextMplsTreatment.
/**
* Map treatment to set_mpls action.
*/
@Test
public void testNextMplsTreatment() throws Exception {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MPLS_10).build();
PiAction mappedAction = interpreter.mapTreatment(treatment, FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS);
PiActionParam mplsParam = new PiActionParam(FabricConstants.LABEL, MPLS_10.toInt());
PiAction expectedAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_MPLS_LABEL).withParameter(mplsParam).build();
assertEquals(expectedAction, mappedAction);
}
Aggregations