jiangrui
Committed by Gerrit Code Review

ONOS-3404 Change p2p tunnel to p2any tunnel by using set tunnel_dst in

flow.

Change-Id: I06cb6d42772434de9c016e795de5c6d8a6f45dfb
......@@ -15,6 +15,7 @@
*/
package org.onosproject.vtn.table;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
......@@ -22,13 +23,14 @@ import org.onosproject.net.flowobjective.Objective;
import org.onosproject.vtnrsc.SegmentationId;
/**
* Applies L2 flows to the device.
* Applies L2 flows to the device. L2Forward table is Table(50).
*/
public interface L2ForwardService {
/**
* The local broadcast rule that message matches Table(50) Match: broadcast
* mac and vnid Action: output port.
* The local broadcast rule that message matches Table(50).
* Match: broadcast mac and vnid.
* Action: set output port.
*
* @param deviceId Device Id
* @param segmentationId the vnid of the host belong to
......@@ -45,8 +47,9 @@ public interface L2ForwardService {
Objective.Operation type);
/**
* The tunnel broadcast rule that message matches Table(50) Match: broadcast
* mac and vnid Action: output port.
* The tunnel broadcast rule that message matches Table(50).
* Match: broadcast mac and vnid.
* Action: output port.
*
* @param deviceId Device Id
* @param segmentationId the vnid of the host belong to
......@@ -61,8 +64,9 @@ public interface L2ForwardService {
Objective.Operation type);
/**
* The local out rule that message matches. Table(50) Match: local host mac
* and vnid Action: output local host port.
* The local out rule that message matches Table(50).
* Match: local host mac and vnid.
* Action: output local host port.
*
* @param deviceId Device Id
* @param segmentationId the vnid of the host belong to
......@@ -75,17 +79,19 @@ public interface L2ForwardService {
Objective.Operation type);
/**
* The tunnel out rule that message matches. Table(50) Match: host mac and
* vnid Action: output tunnel port.
* The tunnel out rule that message matches Table(50).
* Match: host mac and vnid.
* Action: output tunnel port.
*
* @param deviceId Device Id
* @param segmentationId the vnid of the host belong to
* @param tunnelOutPort the port of the tunnel
* @param dstMac the mac of the host
* @param type the operation of the flow
* @param ipAddress the ipAddress of the node
*/
void programTunnelOut(DeviceId deviceId, SegmentationId segmentationId,
PortNumber tunnelOutPort, MacAddress dstMac,
Objective.Operation type);
Objective.Operation type, IpAddress ipAddress);
}
......
......@@ -16,19 +16,28 @@
package org.onosproject.vtn.table.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST;
import static org.slf4j.LoggerFactory.getLogger;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onlab.osgi.ServiceDirectory;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment.Builder;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flowobjective.DefaultForwardingObjective;
import org.onosproject.net.flowobjective.FlowObjectiveService;
import org.onosproject.net.flowobjective.ForwardingObjective;
......@@ -47,10 +56,10 @@ public final class L2ForwardServiceImpl implements L2ForwardService {
private final Logger log = getLogger(getClass());
private static final int MAC_PRIORITY = 0xffff;
public static final Integer GROUP_ID = 1;
private final FlowObjectiveService flowObjectiveService;
private final ApplicationId appId;
private final DriverService driverService;
/**
* Constructor.
*
......@@ -60,6 +69,7 @@ public final class L2ForwardServiceImpl implements L2ForwardService {
this.appId = checkNotNull(appId, "ApplicationId can not be null");
ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class);
this.driverService = serviceDirectory.get(DriverService.class);
}
@Override
......@@ -91,9 +101,7 @@ public final class L2ForwardServiceImpl implements L2ForwardService {
if (type.equals(Objective.Operation.REMOVE) && inPort == lp) {
flag = false;
}
for (PortNumber outport : localTunnelPorts) {
treatment.setOutput(outport);
}
treatment.group(new DefaultGroupId(GROUP_ID));
ForwardingObjective.Builder objective = DefaultForwardingObjective
.builder().withTreatment(treatment.build())
.withSelector(selector).fromApp(appId).makePermanent()
......@@ -171,15 +179,26 @@ public final class L2ForwardServiceImpl implements L2ForwardService {
public void programTunnelOut(DeviceId deviceId,
SegmentationId segmentationId,
PortNumber tunnelOutPort, MacAddress dstMac,
Objective.Operation type) {
Objective.Operation type, IpAddress ipAddress) {
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(dstMac).add(Criteria.matchTunnelId(Long
.parseLong(segmentationId.toString())))
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
DriverHandler handler = driverService.createHandler(deviceId);
ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
try {
treatment.setPropertyValue("tunnelDst", Ip4Address.valueOf(ipAddress.toString()));
} catch (Exception e) {
log.error("Failed to get extension instruction to set tunnel dst {}", deviceId);
}
Builder builder = DefaultTrafficTreatment.builder();
builder.extension(treatment, deviceId)
.setOutput(tunnelOutPort).build();
ForwardingObjective.Builder objective = DefaultForwardingObjective
.builder().withTreatment(treatment).withSelector(selector)
.builder().withTreatment(builder.build()).withSelector(selector)
.fromApp(appId).withFlag(Flag.SPECIFIC)
.withPriority(MAC_PRIORITY);
if (type.equals(Objective.Operation.ADD)) {
......@@ -189,5 +208,4 @@ public final class L2ForwardServiceImpl implements L2ForwardService {
}
}
}
......
......@@ -15,9 +15,12 @@
*/
package org.onosproject.vtn.util;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.BridgeConfig;
import org.onosproject.net.behaviour.BridgeName;
......@@ -26,6 +29,7 @@ import org.onosproject.net.behaviour.IpTunnelEndPoint;
import org.onosproject.net.behaviour.TunnelConfig;
import org.onosproject.net.behaviour.TunnelDescription;
import org.onosproject.net.behaviour.TunnelEndPoint;
import org.onosproject.net.behaviour.TunnelName;
import org.onosproject.net.driver.DriverHandler;
/**
......@@ -34,7 +38,13 @@ import org.onosproject.net.driver.DriverHandler;
public final class VtnConfig {
private static final String DEFAULT_BRIDGE_NAME = "br-int";
private static final String DEFAULT_TUNNEL = "vxlan-0.0.0.0";
private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() {
{
put("key", "flow");
put("remote_ip", "flow");
}
};
/**
* Constructs a vtn config object. Utility classes should not have a
* public or default constructor, otherwise IDE will compile unsuccessfully. This
......@@ -64,15 +74,19 @@ public final class VtnConfig {
*/
public static void applyTunnelConfig(DriverHandler handler, IpAddress srcIp,
IpAddress dstIp) {
DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder();
for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) {
optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key));
}
TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class);
TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
TunnelDescription tunnel = new DefaultTunnelDescription(
tunnelAsSrc,
tunnelAsDst,
null,
TunnelDescription.Type.VXLAN,
null);
tunnelConfig.createTunnel(tunnel);
TunnelName.tunnelName(DEFAULT_TUNNEL),
optionBuilder.build());
tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), tunnel);
}
/**
......