Committed by
Gerrit Code Review
ONOS-3404 Change p2p tunnel to p2any tunnel by using set tunnel_dst in
flow. Change-Id: I06cb6d42772434de9c016e795de5c6d8a6f45dfb
Showing
4 changed files
with
62 additions
and
24 deletions
This diff is collapsed. Click to expand it.
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.vtn.table; | 16 | package org.onosproject.vtn.table; |
| 17 | 17 | ||
| 18 | +import org.onlab.packet.IpAddress; | ||
| 18 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
| 19 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.PortNumber; | 21 | import org.onosproject.net.PortNumber; |
| ... | @@ -22,13 +23,14 @@ import org.onosproject.net.flowobjective.Objective; | ... | @@ -22,13 +23,14 @@ import org.onosproject.net.flowobjective.Objective; |
| 22 | import org.onosproject.vtnrsc.SegmentationId; | 23 | import org.onosproject.vtnrsc.SegmentationId; |
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | - * Applies L2 flows to the device. | 26 | + * Applies L2 flows to the device. L2Forward table is Table(50). |
| 26 | */ | 27 | */ |
| 27 | public interface L2ForwardService { | 28 | public interface L2ForwardService { |
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | - * The local broadcast rule that message matches Table(50) Match: broadcast | 31 | + * The local broadcast rule that message matches Table(50). |
| 31 | - * mac and vnid Action: output port. | 32 | + * Match: broadcast mac and vnid. |
| 33 | + * Action: set output port. | ||
| 32 | * | 34 | * |
| 33 | * @param deviceId Device Id | 35 | * @param deviceId Device Id |
| 34 | * @param segmentationId the vnid of the host belong to | 36 | * @param segmentationId the vnid of the host belong to |
| ... | @@ -45,8 +47,9 @@ public interface L2ForwardService { | ... | @@ -45,8 +47,9 @@ public interface L2ForwardService { |
| 45 | Objective.Operation type); | 47 | Objective.Operation type); |
| 46 | 48 | ||
| 47 | /** | 49 | /** |
| 48 | - * The tunnel broadcast rule that message matches Table(50) Match: broadcast | 50 | + * The tunnel broadcast rule that message matches Table(50). |
| 49 | - * mac and vnid Action: output port. | 51 | + * Match: broadcast mac and vnid. |
| 52 | + * Action: output port. | ||
| 50 | * | 53 | * |
| 51 | * @param deviceId Device Id | 54 | * @param deviceId Device Id |
| 52 | * @param segmentationId the vnid of the host belong to | 55 | * @param segmentationId the vnid of the host belong to |
| ... | @@ -61,8 +64,9 @@ public interface L2ForwardService { | ... | @@ -61,8 +64,9 @@ public interface L2ForwardService { |
| 61 | Objective.Operation type); | 64 | Objective.Operation type); |
| 62 | 65 | ||
| 63 | /** | 66 | /** |
| 64 | - * The local out rule that message matches. Table(50) Match: local host mac | 67 | + * The local out rule that message matches Table(50). |
| 65 | - * and vnid Action: output local host port. | 68 | + * Match: local host mac and vnid. |
| 69 | + * Action: output local host port. | ||
| 66 | * | 70 | * |
| 67 | * @param deviceId Device Id | 71 | * @param deviceId Device Id |
| 68 | * @param segmentationId the vnid of the host belong to | 72 | * @param segmentationId the vnid of the host belong to |
| ... | @@ -75,17 +79,19 @@ public interface L2ForwardService { | ... | @@ -75,17 +79,19 @@ public interface L2ForwardService { |
| 75 | Objective.Operation type); | 79 | Objective.Operation type); |
| 76 | 80 | ||
| 77 | /** | 81 | /** |
| 78 | - * The tunnel out rule that message matches. Table(50) Match: host mac and | 82 | + * The tunnel out rule that message matches Table(50). |
| 79 | - * vnid Action: output tunnel port. | 83 | + * Match: host mac and vnid. |
| 84 | + * Action: output tunnel port. | ||
| 80 | * | 85 | * |
| 81 | * @param deviceId Device Id | 86 | * @param deviceId Device Id |
| 82 | * @param segmentationId the vnid of the host belong to | 87 | * @param segmentationId the vnid of the host belong to |
| 83 | * @param tunnelOutPort the port of the tunnel | 88 | * @param tunnelOutPort the port of the tunnel |
| 84 | * @param dstMac the mac of the host | 89 | * @param dstMac the mac of the host |
| 85 | * @param type the operation of the flow | 90 | * @param type the operation of the flow |
| 91 | + * @param ipAddress the ipAddress of the node | ||
| 86 | */ | 92 | */ |
| 87 | void programTunnelOut(DeviceId deviceId, SegmentationId segmentationId, | 93 | void programTunnelOut(DeviceId deviceId, SegmentationId segmentationId, |
| 88 | PortNumber tunnelOutPort, MacAddress dstMac, | 94 | PortNumber tunnelOutPort, MacAddress dstMac, |
| 89 | - Objective.Operation type); | 95 | + Objective.Operation type, IpAddress ipAddress); |
| 90 | 96 | ||
| 91 | } | 97 | } | ... | ... |
| ... | @@ -16,19 +16,28 @@ | ... | @@ -16,19 +16,28 @@ |
| 16 | package org.onosproject.vtn.table.impl; | 16 | package org.onosproject.vtn.table.impl; |
| 17 | 17 | ||
| 18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | +import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST; | ||
| 19 | import static org.slf4j.LoggerFactory.getLogger; | 20 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | 21 | ||
| 21 | import org.onlab.osgi.DefaultServiceDirectory; | 22 | import org.onlab.osgi.DefaultServiceDirectory; |
| 22 | import org.onlab.osgi.ServiceDirectory; | 23 | import org.onlab.osgi.ServiceDirectory; |
| 24 | +import org.onlab.packet.Ip4Address; | ||
| 25 | +import org.onlab.packet.IpAddress; | ||
| 23 | import org.onlab.packet.MacAddress; | 26 | import org.onlab.packet.MacAddress; |
| 24 | import org.onosproject.core.ApplicationId; | 27 | import org.onosproject.core.ApplicationId; |
| 28 | +import org.onosproject.core.DefaultGroupId; | ||
| 25 | import org.onosproject.net.DeviceId; | 29 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.PortNumber; | 30 | import org.onosproject.net.PortNumber; |
| 31 | +import org.onosproject.net.behaviour.ExtensionTreatmentResolver; | ||
| 32 | +import org.onosproject.net.driver.DriverHandler; | ||
| 33 | +import org.onosproject.net.driver.DriverService; | ||
| 27 | import org.onosproject.net.flow.DefaultTrafficSelector; | 34 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 28 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 29 | import org.onosproject.net.flow.TrafficSelector; | 36 | import org.onosproject.net.flow.TrafficSelector; |
| 30 | import org.onosproject.net.flow.TrafficTreatment; | 37 | import org.onosproject.net.flow.TrafficTreatment; |
| 38 | +import org.onosproject.net.flow.TrafficTreatment.Builder; | ||
| 31 | import org.onosproject.net.flow.criteria.Criteria; | 39 | import org.onosproject.net.flow.criteria.Criteria; |
| 40 | +import org.onosproject.net.flow.instructions.ExtensionTreatment; | ||
| 32 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; | 41 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 33 | import org.onosproject.net.flowobjective.FlowObjectiveService; | 42 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 34 | import org.onosproject.net.flowobjective.ForwardingObjective; | 43 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| ... | @@ -47,10 +56,10 @@ public final class L2ForwardServiceImpl implements L2ForwardService { | ... | @@ -47,10 +56,10 @@ public final class L2ForwardServiceImpl implements L2ForwardService { |
| 47 | private final Logger log = getLogger(getClass()); | 56 | private final Logger log = getLogger(getClass()); |
| 48 | 57 | ||
| 49 | private static final int MAC_PRIORITY = 0xffff; | 58 | private static final int MAC_PRIORITY = 0xffff; |
| 50 | - | 59 | + public static final Integer GROUP_ID = 1; |
| 51 | private final FlowObjectiveService flowObjectiveService; | 60 | private final FlowObjectiveService flowObjectiveService; |
| 52 | private final ApplicationId appId; | 61 | private final ApplicationId appId; |
| 53 | - | 62 | + private final DriverService driverService; |
| 54 | /** | 63 | /** |
| 55 | * Constructor. | 64 | * Constructor. |
| 56 | * | 65 | * |
| ... | @@ -60,6 +69,7 @@ public final class L2ForwardServiceImpl implements L2ForwardService { | ... | @@ -60,6 +69,7 @@ public final class L2ForwardServiceImpl implements L2ForwardService { |
| 60 | this.appId = checkNotNull(appId, "ApplicationId can not be null"); | 69 | this.appId = checkNotNull(appId, "ApplicationId can not be null"); |
| 61 | ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); | 70 | ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); |
| 62 | this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); | 71 | this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class); |
| 72 | + this.driverService = serviceDirectory.get(DriverService.class); | ||
| 63 | } | 73 | } |
| 64 | 74 | ||
| 65 | @Override | 75 | @Override |
| ... | @@ -91,9 +101,7 @@ public final class L2ForwardServiceImpl implements L2ForwardService { | ... | @@ -91,9 +101,7 @@ public final class L2ForwardServiceImpl implements L2ForwardService { |
| 91 | if (type.equals(Objective.Operation.REMOVE) && inPort == lp) { | 101 | if (type.equals(Objective.Operation.REMOVE) && inPort == lp) { |
| 92 | flag = false; | 102 | flag = false; |
| 93 | } | 103 | } |
| 94 | - for (PortNumber outport : localTunnelPorts) { | 104 | + treatment.group(new DefaultGroupId(GROUP_ID)); |
| 95 | - treatment.setOutput(outport); | ||
| 96 | - } | ||
| 97 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 105 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 98 | .builder().withTreatment(treatment.build()) | 106 | .builder().withTreatment(treatment.build()) |
| 99 | .withSelector(selector).fromApp(appId).makePermanent() | 107 | .withSelector(selector).fromApp(appId).makePermanent() |
| ... | @@ -171,15 +179,26 @@ public final class L2ForwardServiceImpl implements L2ForwardService { | ... | @@ -171,15 +179,26 @@ public final class L2ForwardServiceImpl implements L2ForwardService { |
| 171 | public void programTunnelOut(DeviceId deviceId, | 179 | public void programTunnelOut(DeviceId deviceId, |
| 172 | SegmentationId segmentationId, | 180 | SegmentationId segmentationId, |
| 173 | PortNumber tunnelOutPort, MacAddress dstMac, | 181 | PortNumber tunnelOutPort, MacAddress dstMac, |
| 174 | - Objective.Operation type) { | 182 | + Objective.Operation type, IpAddress ipAddress) { |
| 175 | TrafficSelector selector = DefaultTrafficSelector.builder() | 183 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 176 | .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long | 184 | .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long |
| 177 | .parseLong(segmentationId.toString()))) | 185 | .parseLong(segmentationId.toString()))) |
| 178 | .build(); | 186 | .build(); |
| 179 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 187 | + |
| 188 | + DriverHandler handler = driverService.createHandler(deviceId); | ||
| 189 | + ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); | ||
| 190 | + ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type()); | ||
| 191 | + try { | ||
| 192 | + treatment.setPropertyValue("tunnelDst", Ip4Address.valueOf(ipAddress.toString())); | ||
| 193 | + } catch (Exception e) { | ||
| 194 | + log.error("Failed to get extension instruction to set tunnel dst {}", deviceId); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + Builder builder = DefaultTrafficTreatment.builder(); | ||
| 198 | + builder.extension(treatment, deviceId) | ||
| 180 | .setOutput(tunnelOutPort).build(); | 199 | .setOutput(tunnelOutPort).build(); |
| 181 | ForwardingObjective.Builder objective = DefaultForwardingObjective | 200 | ForwardingObjective.Builder objective = DefaultForwardingObjective |
| 182 | - .builder().withTreatment(treatment).withSelector(selector) | 201 | + .builder().withTreatment(builder.build()).withSelector(selector) |
| 183 | .fromApp(appId).withFlag(Flag.SPECIFIC) | 202 | .fromApp(appId).withFlag(Flag.SPECIFIC) |
| 184 | .withPriority(MAC_PRIORITY); | 203 | .withPriority(MAC_PRIORITY); |
| 185 | if (type.equals(Objective.Operation.ADD)) { | 204 | if (type.equals(Objective.Operation.ADD)) { |
| ... | @@ -189,5 +208,4 @@ public final class L2ForwardServiceImpl implements L2ForwardService { | ... | @@ -189,5 +208,4 @@ public final class L2ForwardServiceImpl implements L2ForwardService { |
| 189 | } | 208 | } |
| 190 | 209 | ||
| 191 | } | 210 | } |
| 192 | - | ||
| 193 | } | 211 | } | ... | ... |
| ... | @@ -15,9 +15,12 @@ | ... | @@ -15,9 +15,12 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.vtn.util; | 16 | package org.onosproject.vtn.util; |
| 17 | 17 | ||
| 18 | +import java.util.HashMap; | ||
| 19 | +import java.util.Map; | ||
| 18 | import java.util.Set; | 20 | import java.util.Set; |
| 19 | 21 | ||
| 20 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
| 23 | +import org.onosproject.net.DefaultAnnotations; | ||
| 21 | import org.onosproject.net.PortNumber; | 24 | import org.onosproject.net.PortNumber; |
| 22 | import org.onosproject.net.behaviour.BridgeConfig; | 25 | import org.onosproject.net.behaviour.BridgeConfig; |
| 23 | import org.onosproject.net.behaviour.BridgeName; | 26 | import org.onosproject.net.behaviour.BridgeName; |
| ... | @@ -26,6 +29,7 @@ import org.onosproject.net.behaviour.IpTunnelEndPoint; | ... | @@ -26,6 +29,7 @@ import org.onosproject.net.behaviour.IpTunnelEndPoint; |
| 26 | import org.onosproject.net.behaviour.TunnelConfig; | 29 | import org.onosproject.net.behaviour.TunnelConfig; |
| 27 | import org.onosproject.net.behaviour.TunnelDescription; | 30 | import org.onosproject.net.behaviour.TunnelDescription; |
| 28 | import org.onosproject.net.behaviour.TunnelEndPoint; | 31 | import org.onosproject.net.behaviour.TunnelEndPoint; |
| 32 | +import org.onosproject.net.behaviour.TunnelName; | ||
| 29 | import org.onosproject.net.driver.DriverHandler; | 33 | import org.onosproject.net.driver.DriverHandler; |
| 30 | 34 | ||
| 31 | /** | 35 | /** |
| ... | @@ -34,7 +38,13 @@ import org.onosproject.net.driver.DriverHandler; | ... | @@ -34,7 +38,13 @@ import org.onosproject.net.driver.DriverHandler; |
| 34 | public final class VtnConfig { | 38 | public final class VtnConfig { |
| 35 | 39 | ||
| 36 | private static final String DEFAULT_BRIDGE_NAME = "br-int"; | 40 | private static final String DEFAULT_BRIDGE_NAME = "br-int"; |
| 37 | - | 41 | + private static final String DEFAULT_TUNNEL = "vxlan-0.0.0.0"; |
| 42 | + private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() { | ||
| 43 | + { | ||
| 44 | + put("key", "flow"); | ||
| 45 | + put("remote_ip", "flow"); | ||
| 46 | + } | ||
| 47 | + }; | ||
| 38 | /** | 48 | /** |
| 39 | * Constructs a vtn config object. Utility classes should not have a | 49 | * Constructs a vtn config object. Utility classes should not have a |
| 40 | * public or default constructor, otherwise IDE will compile unsuccessfully. This | 50 | * public or default constructor, otherwise IDE will compile unsuccessfully. This |
| ... | @@ -64,15 +74,19 @@ public final class VtnConfig { | ... | @@ -64,15 +74,19 @@ public final class VtnConfig { |
| 64 | */ | 74 | */ |
| 65 | public static void applyTunnelConfig(DriverHandler handler, IpAddress srcIp, | 75 | public static void applyTunnelConfig(DriverHandler handler, IpAddress srcIp, |
| 66 | IpAddress dstIp) { | 76 | IpAddress dstIp) { |
| 77 | + DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder(); | ||
| 78 | + for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) { | ||
| 79 | + optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key)); | ||
| 80 | + } | ||
| 67 | TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); | 81 | TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); |
| 68 | TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); | 82 | TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); |
| 69 | - TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dstIp); | ||
| 70 | TunnelDescription tunnel = new DefaultTunnelDescription( | 83 | TunnelDescription tunnel = new DefaultTunnelDescription( |
| 71 | tunnelAsSrc, | 84 | tunnelAsSrc, |
| 72 | - tunnelAsDst, | 85 | + null, |
| 73 | TunnelDescription.Type.VXLAN, | 86 | TunnelDescription.Type.VXLAN, |
| 74 | - null); | 87 | + TunnelName.tunnelName(DEFAULT_TUNNEL), |
| 75 | - tunnelConfig.createTunnel(tunnel); | 88 | + optionBuilder.build()); |
| 89 | + tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), tunnel); | ||
| 76 | } | 90 | } |
| 77 | 91 | ||
| 78 | /** | 92 | /** | ... | ... |
-
Please register or login to post a comment