lishuai
Committed by Gerrit Code Review

[ONOS-3659] Submit the modified content of onos-1.4 to onos-master.

Change-Id: Ibdb9897cde6bc7622276178a6087f02c49da2a48
......@@ -20,6 +20,7 @@ import java.util.Iterator;
import org.onlab.packet.MacAddress;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.vtnrsc.SegmentationId;
import org.onosproject.vtnrsc.TenantId;
......@@ -69,4 +70,14 @@ public class VtnRscManagerTestImpl implements VtnRscService {
public DeviceId getSFToSFFMaping(VirtualPortId portId) {
return DeviceId.deviceId("www.google.com");
}
@Override
public void addDeviceIdOfOvsMap(VirtualPortId virtualPortId,
TenantId tenantId, DeviceId deviceId) {
}
@Override
public void removeDeviceIdOfOvsMap(Host host, TenantId tenantId,
DeviceId deviceId) {
}
}
......
......@@ -19,6 +19,7 @@ import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.Exten
import static org.slf4j.LoggerFactory.getLogger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
......@@ -75,9 +76,12 @@ import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostListener;
import org.onosproject.net.host.HostService;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.onosproject.store.service.LogicalClockService;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.Versioned;
import org.onosproject.vtn.manager.VTNService;
import org.onosproject.vtn.table.ArpService;
import org.onosproject.vtn.table.ClassifierService;
......@@ -188,7 +192,7 @@ public class VTNManager implements VTNService {
private final DeviceListener deviceListener = new InnerDeviceListener();
private final VtnRscListener l3EventListener = new VtnL3EventListener();
private static String exPortName = "eth0";
private static final String EX_PORT_KEY = "exPortKey";
private static final String IFACEID = "ifaceid";
private static final String CONTROLLER_IP_KEY = "ipaddress";
public static final String DRIVER_NAME = "onosfw";
......@@ -198,6 +202,7 @@ public class VTNManager implements VTNService {
private static final String ROUTERINF_FLAG_OF_TENANT = "routerInfFlagOfTenant";
private static final String HOSTS_OF_SUBNET = "hostsOfSubnet";
private static final String EX_PORT_OF_DEVICE = "exPortOfDevice";
private static final String EX_PORT_MAP = "exPortMap";
private static final String DEFAULT_IP = "0.0.0.0";
private static final int SUBNET_NUM = 2;
......@@ -207,6 +212,7 @@ public class VTNManager implements VTNService {
private EventuallyConsistentMap<SubnetId, Map<HostId, Host>> hostsOfSubnet;
private EventuallyConsistentMap<TenantId, Boolean> routerInfFlagOfTenant;
private EventuallyConsistentMap<DeviceId, Port> exPortOfDevice;
private static ConsistentMap<String, String> exPortMap;
@Activate
public void activate() {
......@@ -275,6 +281,14 @@ public class VTNManager implements VTNService {
.withTimestampProvider((k, v) -> clockService.getTimestamp())
.build();
exPortMap = storageService
.<String, String>consistentMapBuilder()
.withName(EX_PORT_MAP)
.withApplicationId(appId)
.withPurgeOnUninstall()
.withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API)))
.build();
log.info("Started");
}
......@@ -310,8 +324,11 @@ public class VTNManager implements VTNService {
config.driver(DRIVER_NAME);
configService.applyConfig(deviceId, BasicDeviceConfig.class, config.node());
// Add Bridge
VtnConfig.applyBridgeConfig(handler, dpid, exPortName);
log.info("A new ovs is created in node {}", localIp.toString());
Versioned<String> exPortVersioned = exPortMap.get(EX_PORT_KEY);
if (exPortVersioned != null) {
VtnConfig.applyBridgeConfig(handler, dpid, exPortVersioned.value());
log.info("A new ovs is created in node {}", localIp.toString());
}
switchesOfController.put(localIp, true);
}
// Create tunnel in br-int on all controllers
......@@ -330,8 +347,6 @@ public class VTNManager implements VTNService {
if (mastershipService.isLocalMaster(controllerDeviceId)) {
switchesOfController.remove(dstIpAddress);
}
// remove tunnel in br-int on other controllers
programTunnelConfig(controllerDeviceId, dstIpAddress, null);
}
@Override
......@@ -357,6 +372,7 @@ public class VTNManager implements VTNService {
log.error("The ifaceId of Host is null");
return;
}
programSffAndClassifierHost(host, Objective.Operation.ADD);
// apply L2 openflow rules
applyHostMonitoredL2Rules(host, Objective.Operation.ADD);
// apply L3 openflow rules
......@@ -374,6 +390,7 @@ public class VTNManager implements VTNService {
log.error("The ifaceId of Host is null");
return;
}
programSffAndClassifierHost(host, Objective.Operation.REMOVE);
// apply L2 openflow rules
applyHostMonitoredL2Rules(host, Objective.Operation.REMOVE);
// apply L3 openflow rules
......@@ -463,6 +480,22 @@ public class VTNManager implements VTNService {
}
}
private void programSffAndClassifierHost(Host host, Objective.Operation type) {
DeviceId deviceId = host.location().deviceId();
String ifaceId = host.annotations().value(IFACEID);
VirtualPortId virtualPortId = VirtualPortId.portId(ifaceId);
VirtualPort virtualPort = virtualPortService.getPort(virtualPortId);
if (virtualPort == null) {
virtualPort = VtnData.getPort(vPortStore, virtualPortId);
}
TenantId tenantId = virtualPort.tenantId();
if (Objective.Operation.ADD == type) {
vtnRscService.addDeviceIdOfOvsMap(virtualPortId, tenantId, deviceId);
} else if (Objective.Operation.REMOVE == type) {
vtnRscService.removeDeviceIdOfOvsMap(host, tenantId, deviceId);
}
}
private void applyHostMonitoredL2Rules(Host host, Objective.Operation type) {
DeviceId deviceId = host.location().deviceId();
if (!mastershipService.isLocalMaster(deviceId)) {
......@@ -971,7 +1004,9 @@ public class VTNManager implements VTNService {
Port exPort = null;
for (Port port : ports) {
String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
if (portName != null && portName.equals(exPortName)) {
Versioned<String> exPortVersioned = exPortMap.get(EX_PORT_KEY);
if (portName != null && exPortVersioned != null && portName.
equals(exPortVersioned.value())) {
exPort = port;
break;
}
......@@ -1071,6 +1106,6 @@ public class VTNManager implements VTNService {
}
public static void setExPortName(String name) {
exPortName = name;
exPortMap.put(EX_PORT_KEY, name);
}
}
......
......@@ -176,23 +176,11 @@ public class FloatingIpManager implements FloatingIpService {
boolean result = true;
for (FloatingIp floatingIp : floatingIps) {
verifyFloatingIpData(floatingIp);
if (floatingIp.portId() != null) {
floatingIpStore.put(floatingIp.id(), floatingIp);
if (!floatingIpStore.containsKey(floatingIp.id())) {
log.debug("The floating Ip is created failed whose identifier is {}",
floatingIp.id().toString());
result = false;
}
} else {
FloatingIp oldFloatingIp = floatingIpStore.get(floatingIp.id());
if (oldFloatingIp != null) {
floatingIpStore.remove(floatingIp.id(), oldFloatingIp);
if (floatingIpStore.containsKey(floatingIp.id())) {
log.debug("The floating Ip is created failed whose identifier is {}",
floatingIp.id().toString());
result = false;
}
}
floatingIpStore.put(floatingIp.id(), floatingIp);
if (!floatingIpStore.containsKey(floatingIp.id())) {
log.debug("The floating Ip is created failed whose identifier is {}",
floatingIp.id().toString());
result = false;
}
}
return result;
......@@ -204,23 +192,11 @@ public class FloatingIpManager implements FloatingIpService {
boolean result = true;
for (FloatingIp floatingIp : floatingIps) {
verifyFloatingIpData(floatingIp);
if (floatingIp.portId() != null) {
floatingIpStore.put(floatingIp.id(), floatingIp);
if (!floatingIpStore.containsKey(floatingIp.id())) {
log.debug("The floating Ip is updated failed whose identifier is {}",
floatingIp.id().toString());
result = false;
}
} else {
FloatingIp oldFloatingIp = floatingIpStore.get(floatingIp.id());
if (oldFloatingIp != null) {
floatingIpStore.remove(floatingIp.id(), oldFloatingIp);
if (floatingIpStore.containsKey(floatingIp.id())) {
log.debug("The floating Ip is updated failed whose identifier is {}",
floatingIp.id().toString());
result = false;
}
}
floatingIpStore.put(floatingIp.id(), floatingIp);
if (!floatingIpStore.containsKey(floatingIp.id())) {
log.debug("The floating Ip is updated failed whose identifier is {}",
floatingIp.id().toString());
result = false;
}
}
return result;
......@@ -238,6 +214,11 @@ public class FloatingIpManager implements FloatingIpService {
"FloatingIP ID doesn't exist");
}
FloatingIp floatingIp = floatingIpStore.get(floatingIpId);
if (floatingIp.portId() != null) {
log.debug("The floating Ip is uesd by the port whose identifier is {}",
floatingIp.portId().toString());
return false;
}
floatingIpStore.remove(floatingIpId, floatingIp);
if (floatingIpStore.containsKey(floatingIpId)) {
log.debug("The floating Ip is deleted failed whose identifier is {}",
......
......@@ -21,6 +21,7 @@ import org.onlab.packet.MacAddress;
import org.onosproject.event.ListenerService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.vtnrsc.SegmentationId;
import org.onosproject.vtnrsc.TenantId;
......@@ -79,4 +80,24 @@ public interface VtnRscService extends ListenerService<VtnRscEvent, VtnRscListen
* @return device identifier
*/
DeviceId getSFToSFFMaping(VirtualPortId portId);
/**
* Adds specify Device identifier to Service Function Forward OvsMap
* or Classifier OvsMap.
*
* @param virtualPortId the VirtualPort identifier
* @param tenantId the tenant identifier
* @param deviceId the device identifier
*/
void addDeviceIdOfOvsMap(VirtualPortId virtualPortId, TenantId tenantId, DeviceId deviceId);
/**
* Removes specify Device identifier from Service Function Forward OvsMap
* or Classifier OvsMap.
*
* @param host Host
* @param tenantId the tenant identifier
* @param deviceId the device identifier
*/
void removeDeviceIdOfOvsMap(Host host, TenantId tenantId, DeviceId deviceId);
}
......
......@@ -70,6 +70,7 @@ public class FloatingIpWebResource extends AbstractWebResource {
.getLogger(FloatingIpWebResource.class);
public static final String CREATE_FAIL = "Floating IP is failed to create!";
public static final String UPDATE_FAIL = "Floating IP is failed to update!";
public static final String DELETE_FAIL = "Floating IP is failed to delete!";
public static final String GET_FAIL = "Floating IP is failed to get!";
public static final String NOT_EXIST = "Floating IP does not exist!";
public static final String DELETE_SUCCESS = "Floating IP delete success!";
......@@ -157,7 +158,11 @@ public class FloatingIpWebResource extends AbstractWebResource {
try {
FloatingIpId floatingIpId = FloatingIpId.of(id);
Set<FloatingIpId> floatingIpIds = Sets.newHashSet(floatingIpId);
get(FloatingIpService.class).removeFloatingIps(floatingIpIds);
Boolean result = nullIsNotFound(get(FloatingIpService.class)
.removeFloatingIps(floatingIpIds), DELETE_FAIL);
if (!result) {
return Response.status(CONFLICT).entity(DELETE_FAIL).build();
}
return Response.status(NO_CONTENT).entity(DELETE_SUCCESS).build();
} catch (Exception e) {
return Response.status(NOT_FOUND).entity(e.getMessage()).build();
......