use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.
the class FlowRuleCodecTest method testFlowRuleEncode.
/**
* Checks that a simple rule encodes properly.
*/
@Test
public void testFlowRuleEncode() {
DeviceId deviceId = DeviceId.deviceId("of:000000000000000a");
Instruction output = Instructions.createOutput(PortNumber.portNumber(0));
Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66"));
Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99"));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
TrafficTreatment treatment = tBuilder.add(output).add(modL2Src).add(modL2Dst).build();
Criterion inPort = Criteria.matchInPort(PortNumber.portNumber(0));
Criterion ethSrc = Criteria.matchEthSrc(MacAddress.valueOf("11:22:33:44:55:66"));
Criterion ethDst = Criteria.matchEthDst(MacAddress.valueOf("44:55:66:77:88:99"));
Criterion ethType = Criteria.matchEthType(Ethernet.TYPE_IPV4);
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
TrafficSelector selector = sBuilder.add(inPort).add(ethSrc).add(ethDst).add(ethType).build();
FlowRule permFlowRule = DefaultFlowRule.builder().withCookie(1).forTable(1).withPriority(1).makePermanent().withTreatment(treatment).withSelector(selector).forDevice(deviceId).build();
FlowRule tempFlowRule = DefaultFlowRule.builder().withCookie(1).forTable(1).withPriority(1).makeTemporary(1000).withTreatment(treatment).withSelector(selector).forDevice(deviceId).build();
ObjectNode permFlowRuleJson = flowRuleCodec.encode(permFlowRule, context);
ObjectNode tempFlowRuleJson = flowRuleCodec.encode(tempFlowRule, context);
assertThat(permFlowRuleJson, FlowRuleJsonMatcher.matchesFlowRule(permFlowRule));
assertThat(tempFlowRuleJson, FlowRuleJsonMatcher.matchesFlowRule(tempFlowRule));
}
use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.
the class FlowRuleCodecTest method codecCriteriaFlowTest.
/**
* Checks that a rule with one of each kind of criterion decodes properly.
*
* @throws IOException if the resource cannot be processed
*/
@Test
public void codecCriteriaFlowTest() throws Exception {
FlowRule rule = getRule("criteria-flow.json");
checkCommonData(rule);
assertThat(rule.selector().criteria().size(), is(35));
rule.selector().criteria().forEach(criterion -> criteria.put(criterion.type().name(), criterion));
Criterion criterion;
criterion = getCriterion(Criterion.Type.ETH_TYPE);
assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
criterion = getCriterion(Criterion.Type.ETH_DST);
assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
criterion = getCriterion(Criterion.Type.ETH_SRC);
assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
criterion = getCriterion(Criterion.Type.IN_PORT);
assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(23)));
criterion = getCriterion(Criterion.Type.IN_PHY_PORT);
assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(44)));
criterion = getCriterion(Criterion.Type.VLAN_VID);
assertThat(((VlanIdCriterion) criterion).vlanId(), is(VlanId.vlanId((short) 777)));
criterion = getCriterion(Criterion.Type.VLAN_PCP);
assertThat(((VlanPcpCriterion) criterion).priority(), is(((byte) 3)));
criterion = getCriterion(Criterion.Type.IP_DSCP);
assertThat(((IPDscpCriterion) criterion).ipDscp(), is(((byte) 2)));
criterion = getCriterion(Criterion.Type.IP_ECN);
assertThat(((IPEcnCriterion) criterion).ipEcn(), is(((byte) 1)));
criterion = getCriterion(Criterion.Type.IP_PROTO);
assertThat(((IPProtocolCriterion) criterion).protocol(), is(((short) 4)));
criterion = getCriterion(Criterion.Type.IPV4_SRC);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("1.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.IPV4_DST);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("2.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.IPV6_SRC);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("3.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.IPV6_DST);
assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("4.2.0.0/32"))));
criterion = getCriterion(Criterion.Type.TCP_SRC);
assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(80));
criterion = getCriterion(Criterion.Type.TCP_DST);
assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(443));
criterion = getCriterion(Criterion.Type.UDP_SRC);
assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(180));
criterion = getCriterion(Criterion.Type.UDP_DST);
assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(1443));
criterion = getCriterion(Criterion.Type.SCTP_SRC);
assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(280));
criterion = getCriterion(Criterion.Type.SCTP_DST);
assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(2443));
criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
assertThat(((IcmpTypeCriterion) criterion).icmpType(), is((short) 24));
criterion = getCriterion(Criterion.Type.ICMPV4_CODE);
assertThat(((IcmpCodeCriterion) criterion).icmpCode(), is((short) 16));
criterion = getCriterion(Criterion.Type.ICMPV6_TYPE);
assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(), is((short) 14));
criterion = getCriterion(Criterion.Type.ICMPV6_CODE);
assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(), is((short) 6));
criterion = getCriterion(Criterion.Type.IPV6_FLABEL);
assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(), is(8));
criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET);
assertThat(((IPv6NDTargetAddressCriterion) criterion).targetAddress().toString(), is("1111:2222:3333:4444:5555:6666:7777:8888"));
criterion = getCriterion(Criterion.Type.IPV6_ND_SLL);
assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:56")));
criterion = getCriterion(Criterion.Type.IPV6_ND_TLL);
assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:57")));
criterion = getCriterion(Criterion.Type.MPLS_LABEL);
assertThat(((MplsCriterion) criterion).label(), is(MplsLabel.mplsLabel(123)));
criterion = getCriterion(Criterion.Type.IPV6_EXTHDR);
assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(), is(99));
criterion = getCriterion(Criterion.Type.TUNNEL_ID);
assertThat(((TunnelIdCriterion) criterion).tunnelId(), is(100L));
criterion = getCriterion(Criterion.Type.OCH_SIGTYPE);
assertThat(((OchSignalTypeCriterion) criterion).signalType(), is(OchSignalType.FIXED_GRID));
criterion = getCriterion(Criterion.Type.ODU_SIGTYPE);
assertThat(((OduSignalTypeCriterion) criterion).signalType(), is(OduSignalType.ODU4));
criterion = getCriterion(Criterion.Type.ODU_SIGID);
assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributaryPortNumber(), is(1));
assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotLength(), is(80));
assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotBitmap(), is(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));
}
use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.
the class ForwardingObjectiveCodecTest method testForwardingObjectiveEncode.
/**
* Tests encoding of a ForwardingObjective object.
*/
@Test
public void testForwardingObjectiveEncode() {
Criterion criterion1 = Criteria.matchVlanId(VlanId.ANY);
Criterion criterion2 = Criteria.matchEthType((short) 0x8844);
TrafficSelector selector = DefaultTrafficSelector.builder().add(criterion1).add(criterion2).build();
ForwardingObjective forwardingObj = DefaultForwardingObjective.builder().makePermanent().fromApp(APP_ID).withPriority(60).withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(1).withSelector(selector).add();
ObjectNode forwardingObjJson = forwardingObjectiveCodec.encode(forwardingObj, context);
assertThat(forwardingObjJson, matchesForwardingObjective(forwardingObj));
}
use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.
the class FilteringObjectiveCodec method encode.
@Override
public ObjectNode encode(FilteringObjective filteringObjective, CodecContext context) {
checkNotNull(filteringObjective, NOT_NULL_MESSAGE);
final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class);
final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
// encode common properties
ObjectiveCodecHelper och = new ObjectiveCodecHelper();
ObjectNode result = och.encode(filteringObjective, context);
// encode id
result.put(ID, filteringObjective.id());
// encode type
result.put(TYPE, filteringObjective.type().toString());
// encode key
if (filteringObjective.key() != null) {
ObjectNode criterionNode = criterionCodec.encode(filteringObjective.key(), context);
result.set(KEY, criterionNode);
}
// encode meta
if (filteringObjective.meta() != null) {
ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(filteringObjective.meta(), context);
result.set(META, trafficTreatmentNode);
}
// encode conditions
ArrayNode conditions = context.mapper().createArrayNode();
filteringObjective.conditions().forEach(c -> {
ObjectNode criterionJson = criterionCodec.encode(c, context);
conditions.add(criterionJson);
});
result.set(CONDITIONS, conditions);
return result;
}
use of org.onosproject.net.flow.criteria.Criterion in project onos by opennetworkinglab.
the class OfdpaPipelineTraceable method translateInstruction.
// Applies an instruction to the packet in the form of a selector
private TrafficSelector.Builder translateInstruction(TrafficSelector.Builder newSelector, Instruction instruction) {
log.debug("Translating instruction {}", instruction);
log.debug("New Selector {}", newSelector.build());
// TODO add as required
Criterion criterion = null;
if (instruction.type() == Instruction.Type.L2MODIFICATION) {
L2ModificationInstruction l2Instruction = (L2ModificationInstruction) instruction;
switch(l2Instruction.subtype()) {
case VLAN_ID:
ModVlanIdInstruction vlanIdInstruction = (ModVlanIdInstruction) instruction;
VlanId id = vlanIdInstruction.vlanId();
criterion = Criteria.matchVlanId(id);
break;
case VLAN_POP:
criterion = Criteria.matchVlanId(VlanId.NONE);
break;
case MPLS_PUSH:
L2ModificationInstruction.ModMplsHeaderInstruction mplsEthInstruction = (L2ModificationInstruction.ModMplsHeaderInstruction) instruction;
criterion = Criteria.matchEthType(mplsEthInstruction.ethernetType().toShort());
// When pushing MPLS adding metadata to remember the original ethtype
if (isHardwareSwitch()) {
TrafficSelector temporaryPacket = newSelector.build();
Criterion ethCriterion = temporaryPacket.getCriterion(Criterion.Type.ETH_TYPE);
if (ethCriterion != null) {
TrafficSelector.Builder tempSelector = DefaultTrafficSelector.builder(temporaryPacket);
// Store the old ether type for the
tempSelector.matchMetadata(((EthTypeCriterion) ethCriterion).ethType().toShort());
newSelector = tempSelector;
}
}
break;
case MPLS_POP:
L2ModificationInstruction.ModMplsHeaderInstruction mplsPopInstruction = (L2ModificationInstruction.ModMplsHeaderInstruction) instruction;
criterion = Criteria.matchEthType(mplsPopInstruction.ethernetType().toShort());
// When popping MPLS we remove label and BOS
TrafficSelector temporaryPacket = newSelector.build();
if (temporaryPacket.getCriterion(Criterion.Type.MPLS_LABEL) != null) {
TrafficSelector.Builder noMplsSelector = DefaultTrafficSelector.builder();
temporaryPacket.criteria().stream().filter(c -> !c.type().equals(Criterion.Type.MPLS_LABEL) && !c.type().equals(Criterion.Type.MPLS_BOS)).forEach(noMplsSelector::add);
newSelector = noMplsSelector;
}
break;
case MPLS_LABEL:
L2ModificationInstruction.ModMplsLabelInstruction mplsLabelInstruction = (L2ModificationInstruction.ModMplsLabelInstruction) instruction;
criterion = Criteria.matchMplsLabel(mplsLabelInstruction.label());
newSelector.matchMplsBos(true);
break;
case ETH_DST:
L2ModificationInstruction.ModEtherInstruction modEtherDstInstruction = (L2ModificationInstruction.ModEtherInstruction) instruction;
criterion = Criteria.matchEthDst(modEtherDstInstruction.mac());
break;
case ETH_SRC:
L2ModificationInstruction.ModEtherInstruction modEtherSrcInstruction = (L2ModificationInstruction.ModEtherInstruction) instruction;
criterion = Criteria.matchEthSrc(modEtherSrcInstruction.mac());
break;
default:
log.debug("Unsupported L2 Instruction");
break;
}
} else {
log.debug("Unsupported Instruction");
}
if (criterion != null) {
log.debug("Adding criterion {}", criterion);
newSelector.add(criterion);
}
return newSelector;
}
Aggregations