use of org.onosproject.net.flow.criteria.IPCriterion 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.IPCriterion in project onos by opennetworkinglab.
the class OvsOfdpaPipeline method processDoubleTaggedFwd.
/**
* Handles forwarding rules to the IP Unicast Routing.
*
* @param fwd the forwarding objective
* @return A collection of flow rules, or an empty set
*/
protected Collection<FlowRule> processDoubleTaggedFwd(ForwardingObjective fwd) {
// inner for UNICAST_ROUTING_TABLE_1, outer for UNICAST_ROUTING_TABLE
TrafficSelector selector = fwd.selector();
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder innerTtb = DefaultTrafficTreatment.builder();
TrafficTreatment.Builder outerTtb = DefaultTrafficTreatment.builder();
EthTypeCriterion ethType = (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
sBuilder.matchEthType(Ethernet.TYPE_IPV4);
sBuilder.matchVlanId(VlanId.ANY);
IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
if (!ipv4Dst.isMulticast() && ipv4Dst.prefixLength() == 32) {
sBuilder.matchIPDst(ipv4Dst);
if (fwd.nextId() != null) {
NextGroup next = getGroupForNextObjective(fwd.nextId());
if (next != null) {
List<Deque<GroupKey>> gkeys = appKryo.deserialize(next.data());
// we only need the top level group's key to point the flow to it
Group group = groupService.getGroup(deviceId, gkeys.get(0).peekFirst());
if (group == null) {
log.warn("Group with key:{} for next-id:{} not found in dev:{}", gkeys.get(0).peekFirst(), fwd.nextId(), deviceId);
fail(fwd, ObjectiveError.GROUPMISSING);
return Collections.emptySet();
}
outerTtb.immediate().setVlanId(extractDummyVlanIdFromGroupId(group.id().id()));
// ACTSET_OUTPUT in OVS will match output action in write_action() set.
outerTtb.deferred().setOutput(extractOutputPortFromGroupId(group.id().id()));
outerTtb.transition(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
innerTtb.deferred().group(group.id());
innerTtb.transition(ACL_TABLE);
FlowRule.Builder innerRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sBuilder.build()).withTreatment(innerTtb.build()).forTable(UNICAST_ROUTING_TABLE_1);
if (fwd.permanent()) {
innerRuleBuilder.makePermanent();
} else {
innerRuleBuilder.makeTemporary(fwd.timeout());
}
Collection<FlowRule> flowRuleCollection = new HashSet<>();
flowRuleCollection.add(innerRuleBuilder.build());
FlowRule.Builder outerRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sBuilder.build()).withTreatment(outerTtb.build()).forTable(UNICAST_ROUTING_TABLE);
if (fwd.permanent()) {
outerRuleBuilder.makePermanent();
} else {
outerRuleBuilder.makeTemporary(fwd.timeout());
}
flowRuleCollection.add(innerRuleBuilder.build());
flowRuleCollection.add(outerRuleBuilder.build());
return flowRuleCollection;
} else {
log.warn("Cannot find group for nextId:{} in dev:{}. Aborting fwd:{}", fwd.nextId(), deviceId, fwd.id());
fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
return Collections.emptySet();
}
} else {
log.warn("NextId is not specified in fwd:{}", fwd.id());
fail(fwd, ObjectiveError.FLOWINSTALLATIONFAILED);
return Collections.emptySet();
}
}
}
return Collections.emptySet();
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class CentecV350Pipeline method processFilter.
private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
PortCriterion p;
if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
p = (PortCriterion) filt.key();
} else {
log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
fail(filt, ObjectiveError.UNKNOWN);
return;
}
// Convert filtering conditions for switch-intfs into flow rules.
FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
for (Criterion c : filt.conditions()) {
// Here we do a trick to install 2 flow rules to MAC_TABLE and ROUTE_TABLE.
if (c.type() == Criterion.Type.ETH_DST) {
EthCriterion e = (EthCriterion) c;
// Install TMAC flow rule.
log.debug("adding rule for Termination MAC in Filter Table: {}", e.mac());
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchEthDst(e.mac());
// Add IPv4 matching explicitly since we will redirect it to ROUTE Table
// through MAC table.
selector.matchEthType(Ethernet.TYPE_IPV4);
treatment.transition(MAC_TABLE);
FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(FILTER_TABLE_TMAC_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
ops = install ? ops.add(rule) : ops.remove(rule);
// Must install another rule to direct the IPv4 packets that hit TMAC to
// Route table.
log.debug("adding rule for Termination MAC in MAC Table: {}", e.mac());
selector = DefaultTrafficSelector.builder();
treatment = DefaultTrafficTreatment.builder();
selector.matchEthDst(e.mac());
// MAC_Table must have metadata matching configured, use the default metadata.
selector.matchMetadata(DEFAULT_METADATA);
treatment.transition(ROUTE_TABLE);
rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(MAC_TABLE_PRIORITY).fromApp(applicationId).makePermanent().forTable(MAC_TABLE).build();
ops = install ? ops.add(rule) : ops.remove(rule);
} else if (c.type() == Criterion.Type.VLAN_VID) {
VlanIdCriterion v = (VlanIdCriterion) c;
log.debug("adding rule for VLAN: {}", v.vlanId());
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchVlanId(v.vlanId());
selector.matchInPort(p.port());
// Although the accepted packets will be sent to filter table, we must
// explicitly set goto_table instruction here.
treatment.writeMetadata(DEFAULT_METADATA, DEFAULT_METADATA_MASK);
// set default metadata written by PORT_VLAN Table.
treatment.transition(FILTER_TABLE);
// We do not support strip vlan here, treatment.deferred().popVlan();
// PORT_VLAN table only accept 0xffff priority since it does exact match only.
FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(PORT_VLAN_TABLE_PRIORITY).fromApp(applicationId).makePermanent().forTable(PORT_VLAN_TABLE).build();
ops = install ? ops.add(rule) : ops.remove(rule);
} else if (c.type() == Criterion.Type.IPV4_DST) {
IPCriterion ipaddr = (IPCriterion) c;
log.debug("adding IP filtering rules in FILTER table: {}", ipaddr.ip());
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchEthType(Ethernet.TYPE_IPV4);
// router IPs to the controller
selector.matchIPDst(ipaddr.ip());
treatment.setOutput(PortNumber.CONTROLLER);
FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(FILTER_TABLE_CONTROLLER_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
ops = install ? ops.add(rule) : ops.remove(rule);
} else {
log.warn("Driver does not currently process filtering condition" + " of type: {}", c.type());
fail(filt, ObjectiveError.UNSUPPORTED);
}
}
// apply filtering flow rules
flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
pass(filt);
log.info("Applied filtering rules");
}
@Override
public void onError(FlowRuleOperations ops) {
fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
log.info("Failed to apply filtering rules");
}
}));
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class CorsaPipelineV39 method processIpTraffic.
@Override
protected Collection<FlowRule> processIpTraffic(ForwardingObjective fwd, Builder rule) {
IPCriterion ipSrc = (IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_SRC);
if (ipSrc != null) {
log.warn("Driver does not currently handle matching Src IP");
fail(fwd, ObjectiveError.UNSUPPORTED);
return ImmutableSet.of();
}
IPCriterion ipDst = (IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_DST);
if (ipDst != null) {
log.error("Driver handles Dst IP matching as specific forwarding " + "objective, not versatile");
fail(fwd, ObjectiveError.UNSUPPORTED);
return ImmutableSet.of();
}
IPProtocolCriterion ipProto = (IPProtocolCriterion) fwd.selector().getCriterion(Criterion.Type.IP_PROTO);
if (ipProto != null && ipProto.protocol() == IPv4.PROTOCOL_TCP) {
log.warn("Driver automatically punts all packets reaching the " + "LOCAL table to the controller");
pass(fwd);
return ImmutableSet.of();
}
return ImmutableSet.of();
}
use of org.onosproject.net.flow.criteria.IPCriterion in project onos by opennetworkinglab.
the class AbstractCorsaPipeline method processSpecificRoute.
private Collection<FlowRule> processSpecificRoute(ForwardingObjective fwd) {
TrafficSelector filteredSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(((IPCriterion) fwd.selector().getCriterion(Criterion.Type.IPV4_DST)).ip()).build();
TrafficTreatment.Builder tb = processSpecificRoutingTreatment();
if (fwd.nextId() != null) {
NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId());
GroupKey key = appKryo.deserialize(next.data());
Group group = groupService.getGroup(deviceId, key);
if (group == null) {
log.warn("The group left!");
fail(fwd, ObjectiveError.GROUPMISSING);
return ImmutableSet.of();
}
tb.group(group.id());
} else {
log.error("Missing NextObjective ID for ForwardingObjective {}", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return ImmutableSet.of();
}
Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(filteredSelector).withTreatment(tb.build());
ruleBuilder = processSpecificRoutingRule(ruleBuilder);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(fwd.timeout());
}
return Collections.singletonList(ruleBuilder.build());
}
Aggregations