Committed by
Gerrit Code Review
ONOS-1856: Supports ports (~65535) for the tunnel policy
- Add some missing Java docs Change-Id: I0ef750efdb9b667a5b5edbd91cf7b4cc54afd38c
Showing
3 changed files
with
60 additions
and
41 deletions
| ... | @@ -249,6 +249,12 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -249,6 +249,12 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
| 249 | return policyHandler.getPolicies(); | 249 | return policyHandler.getPolicies(); |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | + /** | ||
| 253 | + * Returns the tunnel object with the tunnel ID. | ||
| 254 | + * | ||
| 255 | + * @param tunnelId Tunnel ID | ||
| 256 | + * @return Tunnel reference | ||
| 257 | + */ | ||
| 252 | public Tunnel getTunnel(String tunnelId) { | 258 | public Tunnel getTunnel(String tunnelId) { |
| 253 | return tunnelHandler.getTunnel(tunnelId); | 259 | return tunnelHandler.getTunnel(tunnelId); |
| 254 | } | 260 | } |
| ... | @@ -269,10 +275,12 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -269,10 +275,12 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
| 269 | } | 275 | } |
| 270 | 276 | ||
| 271 | /** | 277 | /** |
| 278 | + * Returns the next objective ID for the NeighborSet given. If the nextObjectiveID does not exist, | ||
| 279 | + * a new one is created and returned. | ||
| 272 | * | 280 | * |
| 273 | - * @param deviceId | 281 | + * @param deviceId Device ID |
| 274 | - * @param ns | 282 | + * @param ns NegighborSet |
| 275 | - * @return | 283 | + * @return next objective ID |
| 276 | */ | 284 | */ |
| 277 | public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) { | 285 | public int getNextObjectiveId(DeviceId deviceId, NeighborSet ns) { |
| 278 | 286 | ||
| ... | @@ -287,10 +295,11 @@ public class SegmentRoutingManager implements SegmentRoutingService { | ... | @@ -287,10 +295,11 @@ public class SegmentRoutingManager implements SegmentRoutingService { |
| 287 | } | 295 | } |
| 288 | 296 | ||
| 289 | /** | 297 | /** |
| 298 | + * Removes the next objective ID. | ||
| 290 | * | 299 | * |
| 291 | - * @param deviceId | 300 | + * @param deviceId Device ID |
| 292 | - * @param objectiveId | 301 | + * @param objectiveId next objective ID to remove |
| 293 | - * @return | 302 | + * @return true, if succeeds, false otherwise |
| 294 | */ | 303 | */ |
| 295 | public boolean removeNextObjective(DeviceId deviceId, int objectiveId) { | 304 | public boolean removeNextObjective(DeviceId deviceId, int objectiveId) { |
| 296 | return groupHandlerMap.get(deviceId).removeGroup(objectiveId); | 305 | return groupHandlerMap.get(deviceId).removeGroup(objectiveId); | ... | ... |
| ... | @@ -26,6 +26,8 @@ import org.onosproject.net.flow.TrafficSelector; | ... | @@ -26,6 +26,8 @@ import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.criteria.Criterion; | 26 | import org.onosproject.net.flow.criteria.Criterion; |
| 27 | import org.onosproject.net.flow.criteria.IPCriterion; | 27 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 28 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; | 28 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 29 | +import org.onosproject.net.flow.criteria.TcpPortCriterion; | ||
| 30 | +import org.onosproject.net.flow.criteria.UdpPortCriterion; | ||
| 29 | import org.onosproject.segmentrouting.Policy; | 31 | import org.onosproject.segmentrouting.Policy; |
| 30 | import org.onosproject.segmentrouting.TunnelPolicy; | 32 | import org.onosproject.segmentrouting.TunnelPolicy; |
| 31 | 33 | ||
| ... | @@ -39,6 +41,8 @@ public final class PolicyCodec extends JsonCodec<Policy> { | ... | @@ -39,6 +41,8 @@ public final class PolicyCodec extends JsonCodec<Policy> { |
| 39 | private static final String DST_IP = "dst_ip"; | 41 | private static final String DST_IP = "dst_ip"; |
| 40 | private static final String SRC_IP = "src_ip"; | 42 | private static final String SRC_IP = "src_ip"; |
| 41 | private static final String PROTO_TYPE = "proto_type"; | 43 | private static final String PROTO_TYPE = "proto_type"; |
| 44 | + private static final String SRC_PORT = "src_tp_port"; | ||
| 45 | + private static final String DST_PORT = "dst_tp_port"; | ||
| 42 | 46 | ||
| 43 | @Override | 47 | @Override |
| 44 | public ObjectNode encode(Policy policy, CodecContext context) { | 48 | public ObjectNode encode(Policy policy, CodecContext context) { |
| ... | @@ -61,6 +65,29 @@ public final class PolicyCodec extends JsonCodec<Policy> { | ... | @@ -61,6 +65,29 @@ public final class PolicyCodec extends JsonCodec<Policy> { |
| 61 | if (policy.selector().getCriterion(Criterion.Type.IP_PROTO) != null) { | 65 | if (policy.selector().getCriterion(Criterion.Type.IP_PROTO) != null) { |
| 62 | IPProtocolCriterion protocolCriterion = | 66 | IPProtocolCriterion protocolCriterion = |
| 63 | (IPProtocolCriterion) policy.selector().getCriterion(Criterion.Type.IP_PROTO); | 67 | (IPProtocolCriterion) policy.selector().getCriterion(Criterion.Type.IP_PROTO); |
| 68 | + result.put(PROTO_TYPE, protocolCriterion.protocol()); | ||
| 69 | + } | ||
| 70 | + if (policy.selector().getCriterion(Criterion.Type.TCP_SRC) != null) { | ||
| 71 | + TcpPortCriterion tcpPortCriterion = | ||
| 72 | + (TcpPortCriterion) policy.selector().getCriterion(Criterion.Type.TCP_SRC); | ||
| 73 | + result.put(SRC_PORT, tcpPortCriterion.toString()); | ||
| 74 | + } else if (policy.selector().getCriterion(Criterion.Type.UDP_SRC) != null) { | ||
| 75 | + UdpPortCriterion udpPortCriterion = | ||
| 76 | + (UdpPortCriterion) policy.selector().getCriterion(Criterion.Type.UDP_SRC); | ||
| 77 | + result.put(SRC_PORT, udpPortCriterion.toString()); | ||
| 78 | + } | ||
| 79 | + if (policy.selector().getCriterion(Criterion.Type.TCP_DST) != null) { | ||
| 80 | + TcpPortCriterion tcpPortCriterion = | ||
| 81 | + (TcpPortCriterion) policy.selector().getCriterion(Criterion.Type.TCP_DST); | ||
| 82 | + result.put(DST_PORT, tcpPortCriterion.toString()); | ||
| 83 | + } else if (policy.selector().getCriterion(Criterion.Type.UDP_DST) != null) { | ||
| 84 | + UdpPortCriterion udpPortCriterion = | ||
| 85 | + (UdpPortCriterion) policy.selector().getCriterion(Criterion.Type.UDP_DST); | ||
| 86 | + result.put(DST_PORT, udpPortCriterion.toString()); | ||
| 87 | + } | ||
| 88 | + if (policy.selector().getCriterion(Criterion.Type.IP_PROTO) != null) { | ||
| 89 | + IPProtocolCriterion protocolCriterion = | ||
| 90 | + (IPProtocolCriterion) policy.selector().getCriterion(Criterion.Type.IP_PROTO); | ||
| 64 | result.put(PROTO_TYPE, protocolCriterion.toString()); | 91 | result.put(PROTO_TYPE, protocolCriterion.toString()); |
| 65 | } | 92 | } |
| 66 | 93 | ||
| ... | @@ -81,6 +108,8 @@ public final class PolicyCodec extends JsonCodec<Policy> { | ... | @@ -81,6 +108,8 @@ public final class PolicyCodec extends JsonCodec<Policy> { |
| 81 | String srcIp = json.path(SRC_IP).asText(); | 108 | String srcIp = json.path(SRC_IP).asText(); |
| 82 | String tunnelId = json.path(TUNNEL_ID).asText(); | 109 | String tunnelId = json.path(TUNNEL_ID).asText(); |
| 83 | String protoType = json.path(PROTO_TYPE).asText(); | 110 | String protoType = json.path(PROTO_TYPE).asText(); |
| 111 | + short srcPort = json.path(SRC_PORT).shortValue(); | ||
| 112 | + short dstPort = json.path(DST_PORT).shortValue(); | ||
| 84 | 113 | ||
| 85 | if (tunnelId != null) { | 114 | if (tunnelId != null) { |
| 86 | TrafficSelector.Builder tsb = DefaultTrafficSelector.builder(); | 115 | TrafficSelector.Builder tsb = DefaultTrafficSelector.builder(); |
| ... | @@ -94,8 +123,22 @@ public final class PolicyCodec extends JsonCodec<Policy> { | ... | @@ -94,8 +123,22 @@ public final class PolicyCodec extends JsonCodec<Policy> { |
| 94 | if (protoType != null && !protoType.isEmpty()) { | 123 | if (protoType != null && !protoType.isEmpty()) { |
| 95 | Short ipProto = Short.valueOf(IpProtocol.valueOf(protoType).value()); | 124 | Short ipProto = Short.valueOf(IpProtocol.valueOf(protoType).value()); |
| 96 | tsb.matchIPProtocol(ipProto.byteValue()); | 125 | tsb.matchIPProtocol(ipProto.byteValue()); |
| 126 | + if (IpProtocol.valueOf(protoType).equals(IpProtocol.TCP)) { | ||
| 127 | + if (srcPort != 0) { | ||
| 128 | + tsb.matchTcpSrc(srcPort); | ||
| 129 | + } | ||
| 130 | + if (dstPort != 0) { | ||
| 131 | + tsb.matchTcpDst(dstPort); | ||
| 132 | + } | ||
| 133 | + } else if (IpProtocol.valueOf(protoType).equals(IpProtocol.UDP)) { | ||
| 134 | + if (srcPort != 0) { | ||
| 135 | + tsb.matchUdpSrc(srcPort); | ||
| 136 | + } | ||
| 137 | + if (dstPort != 0) { | ||
| 138 | + tsb.matchUdpDst(dstPort); | ||
| 139 | + } | ||
| 140 | + } | ||
| 97 | } | 141 | } |
| 98 | - | ||
| 99 | TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(pid); | 142 | TunnelPolicy.Builder tpb = TunnelPolicy.builder().setPolicyId(pid); |
| 100 | if (tunnelId != null) { | 143 | if (tunnelId != null) { |
| 101 | tpb.setTunnelId(tunnelId); | 144 | tpb.setTunnelId(tunnelId); | ... | ... |
| ... | @@ -49,7 +49,6 @@ import org.onosproject.net.flow.criteria.Criterion; | ... | @@ -49,7 +49,6 @@ import org.onosproject.net.flow.criteria.Criterion; |
| 49 | import org.onosproject.net.flow.criteria.EthCriterion; | 49 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 50 | import org.onosproject.net.flow.criteria.EthTypeCriterion; | 50 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 51 | import org.onosproject.net.flow.criteria.IPCriterion; | 51 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 52 | -import org.onosproject.net.flow.criteria.IPProtocolCriterion; | ||
| 53 | import org.onosproject.net.flow.criteria.MplsCriterion; | 52 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| 54 | import org.onosproject.net.flow.criteria.PortCriterion; | 53 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 55 | import org.onosproject.net.flow.criteria.VlanIdCriterion; | 54 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| ... | @@ -393,37 +392,6 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour | ... | @@ -393,37 +392,6 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour |
| 393 | return Collections.emptySet(); | 392 | return Collections.emptySet(); |
| 394 | } | 393 | } |
| 395 | 394 | ||
| 396 | - TrafficSelector.Builder filteredSelectorBuilder = | ||
| 397 | - DefaultTrafficSelector.builder(); | ||
| 398 | - if (ethType.ethType() == Ethernet.TYPE_IPV4) { | ||
| 399 | - IPCriterion ipSrc = (IPCriterion) selector | ||
| 400 | - .getCriterion(Criterion.Type.IPV4_SRC); | ||
| 401 | - IPCriterion ipDst = (IPCriterion) selector | ||
| 402 | - .getCriterion(Criterion.Type.IPV4_DST); | ||
| 403 | - IPProtocolCriterion ipProto = (IPProtocolCriterion) selector | ||
| 404 | - .getCriterion(Criterion.Type.IP_PROTO); | ||
| 405 | - | ||
| 406 | - filteredSelectorBuilder | ||
| 407 | - .matchEthType(Ethernet.TYPE_IPV4); | ||
| 408 | - | ||
| 409 | - if (ipSrc != null) { | ||
| 410 | - filteredSelectorBuilder.matchIPSrc(ipSrc.ip()); | ||
| 411 | - } | ||
| 412 | - if (ipDst != null) { | ||
| 413 | - filteredSelectorBuilder.matchIPDst(ipDst.ip()); | ||
| 414 | - } | ||
| 415 | - if (ipProto != null) { | ||
| 416 | - filteredSelectorBuilder.matchIPProtocol( | ||
| 417 | - Short.valueOf(ipProto.protocol()).byteValue()); | ||
| 418 | - } | ||
| 419 | - | ||
| 420 | - log.debug("processing IPv4 specific forwarding objective"); | ||
| 421 | - } else { | ||
| 422 | - log.warn("VERSATILE forwarding objective does not support {} yet.", | ||
| 423 | - ethType.ethType()); | ||
| 424 | - return Collections.emptySet(); | ||
| 425 | - } | ||
| 426 | - | ||
| 427 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment | 395 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment |
| 428 | .builder(); | 396 | .builder(); |
| 429 | treatmentBuilder.wipeDeferred(); | 397 | treatmentBuilder.wipeDeferred(); |
| ... | @@ -449,12 +417,11 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour | ... | @@ -449,12 +417,11 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour |
| 449 | return Collections.emptySet(); | 417 | return Collections.emptySet(); |
| 450 | } | 418 | } |
| 451 | 419 | ||
| 452 | - TrafficSelector filteredSelector = filteredSelectorBuilder.build(); | ||
| 453 | TrafficTreatment treatment = treatmentBuilder.build(); | 420 | TrafficTreatment treatment = treatmentBuilder.build(); |
| 454 | 421 | ||
| 455 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() | 422 | FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() |
| 456 | .fromApp(fwd.appId()).withPriority(fwd.priority()) | 423 | .fromApp(fwd.appId()).withPriority(fwd.priority()) |
| 457 | - .forDevice(deviceId).withSelector(filteredSelector) | 424 | + .forDevice(deviceId).withSelector(fwd.selector()) |
| 458 | .withTreatment(treatment); | 425 | .withTreatment(treatment); |
| 459 | 426 | ||
| 460 | if (fwd.permanent()) { | 427 | if (fwd.permanent()) { | ... | ... |
-
Please register or login to post a comment