use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class ForwardingObjectiveTranslator method ipv4RoutingRule.
private void ipv4RoutingRule(ForwardingObjective obj, Set<Criterion> criteriaWithMeta, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
final IPCriterion ipDstCriterion = (IPCriterion) criterionNotNull(criteriaWithMeta, Criterion.Type.IPV4_DST);
if (ipDstCriterion.ip().prefixLength() == 0) {
defaultIpv4Route(obj, resultBuilder);
return;
}
final TrafficSelector selector = DefaultTrafficSelector.builder().add(ipDstCriterion).build();
resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4, selector));
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class FabricIntProgrammable method buildWatchlistEntry.
private FlowRule buildWatchlistEntry(IntObjective obj) {
int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
PiActionParam maxHopParam = new PiActionParam(FabricConstants.MAX_HOP, copyFrom(MAXHOP));
PiActionParam instCntParam = new PiActionParam(FabricConstants.INS_CNT, copyFrom(Integer.bitCount(instructionBitmap)));
PiActionParam inst0003Param = new PiActionParam(FabricConstants.INS_MASK0003, copyFrom((instructionBitmap >> 12) & 0xF));
PiActionParam inst0407Param = new PiActionParam(FabricConstants.INS_MASK0407, copyFrom((instructionBitmap >> 8) & 0xF));
PiAction intSourceAction = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_INT_SOURCE_DSCP).withParameter(maxHopParam).withParameter(instCntParam).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(FabricConstants.HDR_L4_SPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
break;
case UDP_SRC:
sBuilder.matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_L4_SPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
break;
case TCP_DST:
sBuilder.matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_L4_DPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK).build());
break;
case UDP_DST:
sBuilder.matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_L4_DPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK).build());
break;
default:
log.warn("Unsupported criterion type: {}", criterion.type());
}
}
return DefaultFlowRule.builder().forDevice(deviceId).withSelector(sBuilder.build()).withTreatment(instTreatment).withPriority(DEFAULT_PRIORITY).forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_TB_INT_SOURCE).fromApp(appId).makePermanent().build();
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class FlowObjectiveCompositionUtil method revertTreatmentSelector.
public static TrafficSelector revertTreatmentSelector(TrafficTreatment trafficTreatment, TrafficSelector trafficSelector) {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
Map<Criterion.Type, Criterion> criterionMap = new HashMap<>();
for (Criterion criterion : trafficSelector.criteria()) {
criterionMap.put(criterion.type(), criterion);
}
for (Instruction instruction : trafficTreatment.allInstructions()) {
switch(instruction.type()) {
case OUTPUT:
break;
case GROUP:
break;
case L0MODIFICATION:
{
L0ModificationInstruction l0 = (L0ModificationInstruction) instruction;
switch(l0.subtype()) {
case OCH:
if (criterionMap.containsKey(Criterion.Type.OCH_SIGID)) {
if (((OchSignalCriterion) criterionMap.get((Criterion.Type.OCH_SIGID))).lambda().equals(((L0ModificationInstruction.ModOchSignalInstruction) l0).lambda())) {
criterionMap.remove(Criterion.Type.OCH_SIGID);
} else {
return null;
}
}
default:
break;
}
break;
}
case L1MODIFICATION:
{
L1ModificationInstruction l1 = (L1ModificationInstruction) instruction;
switch(l1.subtype()) {
case ODU_SIGID:
if (criterionMap.containsKey(Criterion.Type.ODU_SIGID)) {
if (((OduSignalIdCriterion) criterionMap.get((Criterion.Type.ODU_SIGID))).oduSignalId().equals(((L1ModificationInstruction.ModOduSignalIdInstruction) l1).oduSignalId())) {
criterionMap.remove(Criterion.Type.ODU_SIGID);
} else {
return null;
}
}
default:
break;
}
break;
}
case L2MODIFICATION:
{
L2ModificationInstruction l2 = (L2ModificationInstruction) instruction;
switch(l2.subtype()) {
case ETH_SRC:
if (criterionMap.containsKey(Criterion.Type.ETH_SRC)) {
if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_SRC))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
criterionMap.remove(Criterion.Type.ETH_SRC);
} else {
return null;
}
} else {
break;
}
case ETH_DST:
if (criterionMap.containsKey(Criterion.Type.ETH_DST)) {
if (((EthCriterion) criterionMap.get((Criterion.Type.ETH_DST))).mac().equals(((L2ModificationInstruction.ModEtherInstruction) l2).mac())) {
criterionMap.remove(Criterion.Type.ETH_DST);
} else {
return null;
}
} else {
break;
}
case VLAN_ID:
if (criterionMap.containsKey(Criterion.Type.VLAN_VID)) {
if (((VlanIdCriterion) criterionMap.get((Criterion.Type.VLAN_VID))).vlanId().equals(((L2ModificationInstruction.ModVlanIdInstruction) l2).vlanId())) {
criterionMap.remove(Criterion.Type.VLAN_VID);
} else {
return null;
}
} else {
break;
}
case VLAN_PCP:
if (criterionMap.containsKey(Criterion.Type.VLAN_PCP)) {
if (((VlanPcpCriterion) criterionMap.get((Criterion.Type.VLAN_PCP))).priority() == ((L2ModificationInstruction.ModVlanPcpInstruction) l2).vlanPcp()) {
criterionMap.remove(Criterion.Type.VLAN_PCP);
} else {
return null;
}
} else {
break;
}
case MPLS_LABEL:
if (criterionMap.containsKey(Criterion.Type.MPLS_LABEL)) {
if (((MplsCriterion) criterionMap.get((Criterion.Type.MPLS_LABEL))).label().equals(((L2ModificationInstruction.ModMplsLabelInstruction) l2).label())) {
criterionMap.remove(Criterion.Type.ETH_DST);
} else {
return null;
}
} else {
break;
}
default:
break;
}
break;
}
case TABLE:
break;
case L3MODIFICATION:
{
L3ModificationInstruction l3 = (L3ModificationInstruction) instruction;
switch(l3.subtype()) {
case IPV4_SRC:
if (criterionMap.containsKey(Criterion.Type.IPV4_SRC)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV4_SRC);
} else {
return null;
}
} else {
break;
}
case IPV4_DST:
if (criterionMap.containsKey(Criterion.Type.IPV4_DST)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV4_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV4_DST);
} else {
return null;
}
} else {
break;
}
case IPV6_SRC:
if (criterionMap.containsKey(Criterion.Type.IPV6_SRC)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_SRC)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV6_SRC);
} else {
return null;
}
} else {
break;
}
case IPV6_DST:
if (criterionMap.containsKey(Criterion.Type.IPV6_DST)) {
if (((IPCriterion) criterionMap.get(Criterion.Type.IPV6_DST)).ip().contains(((L3ModificationInstruction.ModIPInstruction) l3).ip())) {
criterionMap.remove(Criterion.Type.IPV6_DST);
} else {
return null;
}
} else {
break;
}
case IPV6_FLABEL:
if (criterionMap.containsKey(Criterion.Type.IPV6_FLABEL)) {
if (((IPv6FlowLabelCriterion) criterionMap.get(Criterion.Type.IPV6_FLABEL)).flowLabel() == (((L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3).flowLabel())) {
criterionMap.remove(Criterion.Type.IPV4_SRC);
} else {
return null;
}
} else {
break;
}
default:
break;
}
break;
}
case METADATA:
break;
default:
break;
}
}
for (Criterion criterion : criterionMap.values()) {
selectorBuilder.add(criterion);
}
return selectorBuilder.build();
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testLpmToTernaryTranslation.
@Test
public void testLpmToTernaryTranslation() throws Exception {
IpPrefix ipPrefix = IpPrefix.valueOf("10.0.0.1/23");
int bitWidth = ipPrefix.address().toOctets().length * Byte.SIZE;
IPCriterion criterion = (IPCriterion) Criteria.matchIPDst(ipPrefix);
PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(criterion, fieldId, TERNARY, bitWidth);
ImmutableByteSequence expectedMask = ImmutableByteSequence.prefixOnes(Integer.BYTES, 23);
ImmutableByteSequence expectedValue = ImmutableByteSequence.copyFrom(ipPrefix.address().toOctets());
assertThat(ternaryMatch.mask(), is(expectedMask));
assertThat(ternaryMatch.value(), is(expectedValue));
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testIpCriterion.
@Test
public void testIpCriterion() throws Exception {
IpPrefix prefix1 = IpPrefix.valueOf(random.nextInt(), random.nextInt(32));
int bitWidth = prefix1.address().toOctets().length * 8;
IPCriterion criterion = (IPCriterion) Criteria.matchIPDst(prefix1);
PiLpmFieldMatch lpmMatch = (PiLpmFieldMatch) translateCriterion(criterion, fieldId, LPM, bitWidth);
assertThat(lpmMatch.value().asArray(), is(criterion.ip().address().toOctets()));
assertThat(lpmMatch.prefixLength(), is(criterion.ip().prefixLength()));
}
Aggregations