use of org.onosproject.net.flow.criteria.TcpPortCriterion in project fabric-tna by stratum.
the class FabricIntProgrammable method buildCollectorSelector.
private TrafficSelector buildCollectorSelector(Set<Criterion> criteria) {
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
// We always match packets with valid IPv4 header
PiCriterion.Builder piBuilder = PiCriterion.builder().matchExact(P4InfoConstants.HDR_IPV4_VALID, 1);
for (Criterion criterion : criteria) {
switch(criterion.type()) {
case IP_PROTO:
builder.matchIPProtocol((byte) ((IPProtocolCriterion) criterion).protocol());
break;
case IPV4_SRC:
builder.matchIPSrc(((IPCriterion) criterion).ip());
break;
case IPV4_DST:
builder.matchIPDst(((IPCriterion) criterion).ip());
break;
case TCP_SRC:
// TODO: Match a range of TCP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_SPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), ((TcpPortCriterion) criterion).tcpPort().toInt());
break;
case UDP_SRC:
// TODO: Match a range of UDP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_SPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), ((UdpPortCriterion) criterion).udpPort().toInt());
break;
case TCP_DST:
// TODO: Match a range of TCP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_DPORT, ((TcpPortCriterion) criterion).tcpPort().toInt(), ((TcpPortCriterion) criterion).tcpPort().toInt());
break;
case UDP_DST:
// TODO: Match a range of UDP port
piBuilder.matchRange(P4InfoConstants.HDR_L4_DPORT, ((UdpPortCriterion) criterion).udpPort().toInt(), ((UdpPortCriterion) criterion).udpPort().toInt());
break;
default:
log.warn("Unsupported criterion type: {}", criterion.type());
}
}
return builder.matchPi(piBuilder.build()).build();
}
use of org.onosproject.net.flow.criteria.TcpPortCriterion 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.TcpPortCriterion in project onos by opennetworkinglab.
the class PiCriterionTranslatorsTest method testTcpPortCriterion.
@Test
public void testTcpPortCriterion() throws Exception {
TpPort value1 = TpPort.tpPort(random.nextInt(1 << 16));
TpPort value2 = TpPort.tpPort(random.nextInt(1 << 16));
TpPort mask = TpPort.tpPort(random.nextInt(1 << 16));
int bitWidth = 16;
TcpPortCriterion criterion = (TcpPortCriterion) Criteria.matchTcpDst(value1);
PiExactFieldMatch exactMatch = (PiExactFieldMatch) translateCriterion(criterion, fieldId, EXACT, bitWidth);
TcpPortCriterion maskedCriterion = (TcpPortCriterion) Criteria.matchTcpDstMasked(value2, mask);
PiTernaryFieldMatch ternaryMatch = (PiTernaryFieldMatch) translateCriterion(maskedCriterion, fieldId, TERNARY, bitWidth);
assertThat(exactMatch.value().asReadOnlyBuffer().getShort(), is((short) criterion.tcpPort().toInt()));
assertThat(ternaryMatch.value().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.tcpPort().toInt()));
assertThat(ternaryMatch.mask().asReadOnlyBuffer().getShort(), is((short) maskedCriterion.mask().toInt()));
}
use of org.onosproject.net.flow.criteria.TcpPortCriterion 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.TcpPortCriterion in project onos by opennetworkinglab.
the class StatsFlowRuleManager method getOverlayFlowInfos.
@Override
public Set<FlowInfo> getOverlayFlowInfos() {
Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
// obtain all flow rule entries installed by telemetry app
for (FlowEntry entry : flowRuleService.getFlowEntriesById(telemetryAppId)) {
FlowInfo.Builder fBuilder = new DefaultFlowInfo.DefaultBuilder();
TrafficSelector selector = entry.selector();
IPCriterion srcIp = (IPCriterion) selector.getCriterion(IPV4_SRC);
IPCriterion dstIp = (IPCriterion) selector.getCriterion(IPV4_DST);
IPProtocolCriterion ipProtocol = (IPProtocolCriterion) selector.getCriterion(IP_PROTO);
fBuilder.withFlowType(FLOW_TYPE_SONA).withSrcIp(srcIp.ip()).withDstIp(dstIp.ip());
if (ipProtocol != null) {
fBuilder.withProtocol((byte) ipProtocol.protocol());
if (ipProtocol.protocol() == PROTOCOL_TCP) {
TcpPortCriterion tcpSrc = (TcpPortCriterion) selector.getCriterion(TCP_SRC);
TcpPortCriterion tcpDst = (TcpPortCriterion) selector.getCriterion(TCP_DST);
fBuilder.withSrcPort(tcpSrc.tcpPort());
fBuilder.withDstPort(tcpDst.tcpPort());
} else if (ipProtocol.protocol() == PROTOCOL_UDP) {
UdpPortCriterion udpSrc = (UdpPortCriterion) selector.getCriterion(UDP_SRC);
UdpPortCriterion udpDst = (UdpPortCriterion) selector.getCriterion(UDP_DST);
fBuilder.withSrcPort(udpSrc.udpPort());
fBuilder.withDstPort(udpDst.udpPort());
} else {
log.debug("Other protocol: {}", ipProtocol.protocol());
}
}
fBuilder.withSrcMac(getMacAddress(srcIp.ip().address())).withDstMac(getMacAddress(dstIp.ip().address())).withInputInterfaceId(getInterfaceId(srcIp.ip().address())).withOutputInterfaceId(getInterfaceId(dstIp.ip().address())).withVlanId(getVlanId(srcIp.ip().address())).withDeviceId(entry.deviceId());
StatsInfo.Builder sBuilder = new DefaultStatsInfo.DefaultBuilder();
sBuilder.withStartupTime(System.currentTimeMillis()).withFstPktArrTime(System.currentTimeMillis()).withLstPktOffset((int) (REFRESH_INTERVAL * MILLISECONDS)).withCurrAccPkts((int) entry.packets()).withCurrAccBytes(entry.bytes()).withErrorPkts((short) 0).withDropPkts((short) 0);
fBuilder.withStatsInfo(sBuilder.build());
FlowInfo flowInfo = mergeFlowInfo(fBuilder.build(), fBuilder, sBuilder);
flowInfos.add(flowInfo);
log.debug("FlowInfo: \n{}", flowInfo.toString());
}
return flowInfos;
}
Aggregations