sangho
Committed by Gerrit Code Review

ONOS-1856: Supports ports (~65535) for the tunnel policy

 - Add some missing Java docs

Change-Id: I0ef750efdb9b667a5b5edbd91cf7b4cc54afd38c
......@@ -249,6 +249,12 @@ public class SegmentRoutingManager implements SegmentRoutingService {
return policyHandler.getPolicies();
}
/**
* Returns the tunnel object with the tunnel ID.
*
* @param tunnelId Tunnel ID
* @return Tunnel reference
*/
public Tunnel getTunnel(String tunnelId) {
return tunnelHandler.getTunnel(tunnelId);
}
......@@ -269,10 +275,12 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
/**
* Returns the next objective ID for the NeighborSet given. If the nextObjectiveID does not exist,
* a new one is created and returned.
*
* @param deviceId
* @param ns
* @return
* @param deviceId Device ID
* @param ns NegighborSet
* @return next objective ID
*/
public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) {
......@@ -287,10 +295,11 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
/**
* Removes the next objective ID.
*
* @param deviceId
* @param objectiveId
* @return
* @param deviceId Device ID
* @param objectiveId next objective ID to remove
* @return true, if succeeds, false otherwise
*/
public boolean removeNextObjective(DeviceId deviceId, int objectiveId) {
return groupHandlerMap.get(deviceId).removeGroup(objectiveId);
......
......@@ -26,6 +26,8 @@ import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.IPCriterion;
import org.onosproject.net.flow.criteria.IPProtocolCriterion;
import org.onosproject.net.flow.criteria.TcpPortCriterion;
import org.onosproject.net.flow.criteria.UdpPortCriterion;
import org.onosproject.segmentrouting.Policy;
import org.onosproject.segmentrouting.TunnelPolicy;
......@@ -39,6 +41,8 @@ public final class PolicyCodec extends JsonCodec<Policy> {
private static final String DST_IP = "dst_ip";
private static final String SRC_IP = "src_ip";
private static final String PROTO_TYPE = "proto_type";
private static final String SRC_PORT = "src_tp_port";
private static final String DST_PORT = "dst_tp_port";
@Override
public ObjectNode encode(Policy policy, CodecContext context) {
......@@ -61,6 +65,29 @@ public final class PolicyCodec extends JsonCodec<Policy> {
if (policy.selector().getCriterion(Criterion.Type.IP_PROTO) != null) {
IPProtocolCriterion protocolCriterion =
(IPProtocolCriterion) policy.selector().getCriterion(Criterion.Type.IP_PROTO);
result.put(PROTO_TYPE, protocolCriterion.protocol());
}
if (policy.selector().getCriterion(Criterion.Type.TCP_SRC) != null) {
TcpPortCriterion tcpPortCriterion =
(TcpPortCriterion) policy.selector().getCriterion(Criterion.Type.TCP_SRC);
result.put(SRC_PORT, tcpPortCriterion.toString());
} else if (policy.selector().getCriterion(Criterion.Type.UDP_SRC) != null) {
UdpPortCriterion udpPortCriterion =
(UdpPortCriterion) policy.selector().getCriterion(Criterion.Type.UDP_SRC);
result.put(SRC_PORT, udpPortCriterion.toString());
}
if (policy.selector().getCriterion(Criterion.Type.TCP_DST) != null) {
TcpPortCriterion tcpPortCriterion =
(TcpPortCriterion) policy.selector().getCriterion(Criterion.Type.TCP_DST);
result.put(DST_PORT, tcpPortCriterion.toString());
} else if (policy.selector().getCriterion(Criterion.Type.UDP_DST) != null) {
UdpPortCriterion udpPortCriterion =
(UdpPortCriterion) policy.selector().getCriterion(Criterion.Type.UDP_DST);
result.put(DST_PORT, udpPortCriterion.toString());
}
if (policy.selector().getCriterion(Criterion.Type.IP_PROTO) != null) {
IPProtocolCriterion protocolCriterion =
(IPProtocolCriterion) policy.selector().getCriterion(Criterion.Type.IP_PROTO);
result.put(PROTO_TYPE, protocolCriterion.toString());
}
......@@ -81,6 +108,8 @@ public final class PolicyCodec extends JsonCodec<Policy> {
String srcIp = json.path(SRC_IP).asText();
String tunnelId = json.path(TUNNEL_ID).asText();
String protoType = json.path(PROTO_TYPE).asText();
short srcPort = json.path(SRC_PORT).shortValue();
short dstPort = json.path(DST_PORT).shortValue();
if (tunnelId != null) {
TrafficSelector.Builder tsb = DefaultTrafficSelector.builder();
......@@ -94,8 +123,22 @@ public final class PolicyCodec extends JsonCodec<Policy> {
if (protoType != null && !protoType.isEmpty()) {
Short ipProto = Short.valueOf(IpProtocol.valueOf(protoType).value());
tsb.matchIPProtocol(ipProto.byteValue());
if (IpProtocol.valueOf(protoType).equals(IpProtocol.TCP)) {
if (srcPort != 0) {
tsb.matchTcpSrc(srcPort);
}
if (dstPort != 0) {
tsb.matchTcpDst(dstPort);
}
} else if (IpProtocol.valueOf(protoType).equals(IpProtocol.UDP)) {
if (srcPort != 0) {
tsb.matchUdpSrc(srcPort);
}
if (dstPort != 0) {
tsb.matchUdpDst(dstPort);
}
}
}
TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(pid);
if (tunnelId != null) {
tpb.setTunnelId(tunnelId);
......
......@@ -49,7 +49,6 @@ import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.EthCriterion;
import org.onosproject.net.flow.criteria.EthTypeCriterion;
import org.onosproject.net.flow.criteria.IPCriterion;
import org.onosproject.net.flow.criteria.IPProtocolCriterion;
import org.onosproject.net.flow.criteria.MplsCriterion;
import org.onosproject.net.flow.criteria.PortCriterion;
import org.onosproject.net.flow.criteria.VlanIdCriterion;
......@@ -393,37 +392,6 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour
return Collections.emptySet();
}
TrafficSelector.Builder filteredSelectorBuilder =
DefaultTrafficSelector.builder();
if (ethType.ethType() == Ethernet.TYPE_IPV4) {
IPCriterion ipSrc = (IPCriterion) selector
.getCriterion(Criterion.Type.IPV4_SRC);
IPCriterion ipDst = (IPCriterion) selector
.getCriterion(Criterion.Type.IPV4_DST);
IPProtocolCriterion ipProto = (IPProtocolCriterion) selector
.getCriterion(Criterion.Type.IP_PROTO);
filteredSelectorBuilder
.matchEthType(Ethernet.TYPE_IPV4);
if (ipSrc != null) {
filteredSelectorBuilder.matchIPSrc(ipSrc.ip());
}
if (ipDst != null) {
filteredSelectorBuilder.matchIPDst(ipDst.ip());
}
if (ipProto != null) {
filteredSelectorBuilder.matchIPProtocol(
Short.valueOf(ipProto.protocol()).byteValue());
}
log.debug("processing IPv4 specific forwarding objective");
} else {
log.warn("VERSATILE forwarding objective does not support {} yet.",
ethType.ethType());
return Collections.emptySet();
}
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment
.builder();
treatmentBuilder.wipeDeferred();
......@@ -449,12 +417,11 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour
return Collections.emptySet();
}
TrafficSelector filteredSelector = filteredSelectorBuilder.build();
TrafficTreatment treatment = treatmentBuilder.build();
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
.fromApp(fwd.appId()).withPriority(fwd.priority())
.forDevice(deviceId).withSelector(filteredSelector)
.forDevice(deviceId).withSelector(fwd.selector())
.withTreatment(treatment);
if (fwd.permanent()) {
......