lishuai

[ONOS-4428] Fix the L3 dataflow bug when in same ternant but different

subnet with different routers, in the odler version of ONOS, in the same
ternant, different network with differnent routers, dataflows can be
send to each other successfully.

Change-Id: I6e50289023711eb0f6005efee0efd6f7ab9ec3ee
......@@ -24,6 +24,7 @@ import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.vtnrsc.SegmentationId;
import org.onosproject.vtnrsc.TenantId;
import org.onosproject.vtnrsc.TenantRouter;
import org.onosproject.vtnrsc.VirtualPortId;
import org.onosproject.vtnrsc.event.VtnRscListener;
import org.onosproject.vtnrsc.service.VtnRscService;
......@@ -79,4 +80,9 @@ public class VtnRscAdapter implements VtnRscService {
public void removeDeviceIdOfOvsMap(Host host, TenantId tenantId,
DeviceId deviceId) {
}
@Override
public SegmentationId getL3vni(TenantRouter tenantRouter) {
return null;
}
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Objects;
public final class TenantRouter {
private final TenantId tenantId;
private final RouterId routerId;
/**
* Construct a TenantRouter object.
*
* @param tenantId the tenant identifier
* @param routerId router identifier
*/
private TenantRouter(TenantId tenantId, RouterId routerId) {
this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
this.routerId = checkNotNull(routerId, "routerId cannot be null");
}
/**
* Create a TenantRouter object.
*
* @param tenantId the tenant identifier
* @param routerId router identifier
* @return TenantRouter
*/
public static TenantRouter tenantRouter(TenantId tenantId, RouterId routerId) {
return new TenantRouter(tenantId, routerId);
}
public TenantId tenantId() {
return tenantId;
}
public RouterId routerId() {
return routerId;
}
@Override
public int hashCode() {
return Objects.hash(tenantId, routerId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof TenantRouter) {
final TenantRouter that = (TenantRouter) obj;
return this.getClass() == that.getClass()
&& Objects.equals(this.tenantId, that.tenantId)
&& Objects.equals(this.routerId, that.routerId);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this)
.add("tenantId", tenantId)
.add("routerId", routerId)
.toString();
}
}
......@@ -23,6 +23,7 @@ import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.vtnrsc.SegmentationId;
import org.onosproject.vtnrsc.TenantId;
import org.onosproject.vtnrsc.TenantRouter;
import org.onosproject.vtnrsc.VirtualPortId;
import org.onosproject.vtnrsc.event.VtnRscEvent;
import org.onosproject.vtnrsc.event.VtnRscListener;
......@@ -42,6 +43,14 @@ public interface VtnRscService extends ListenerService<VtnRscEvent, VtnRscListen
SegmentationId getL3vni(TenantId tenantId);
/**
* Returns the SegmentationId of tenantRouter.
*
* @param tenantRouter TenantRouter
* @return SegmentationId the SegmentationId of tenantRouter
*/
SegmentationId getL3vni(TenantRouter tenantRouter);
/**
* Returns Classifier Ovs list of the specific tenant.
*
* @param tenantId tenant identifier
......
......@@ -56,6 +56,7 @@ import org.onosproject.vtnrsc.SegmentationId;
import org.onosproject.vtnrsc.Subnet;
import org.onosproject.vtnrsc.SubnetId;
import org.onosproject.vtnrsc.TenantId;
import org.onosproject.vtnrsc.TenantRouter;
import org.onosproject.vtnrsc.VirtualPort;
import org.onosproject.vtnrsc.VirtualPortId;
import org.onosproject.vtnrsc.event.VtnRscEvent;
......@@ -111,7 +112,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
private FlowClassifierListener flowClassifierListener = new InnerFlowClassifierListener();
private PortChainListener portChainListener = new InnerPortChainListener();
private EventuallyConsistentMap<TenantId, SegmentationId> l3vniMap;
private EventuallyConsistentMap<TenantId, SegmentationId> l3vniTenantMap;
private EventuallyConsistentMap<TenantRouter, SegmentationId> l3vniTenantRouterMap;
private EventuallyConsistentMap<TenantId, Set<DeviceId>> classifierOvsMap;
private EventuallyConsistentMap<TenantId, Set<DeviceId>> sffOvsMap;
......@@ -122,7 +124,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
private static final String DEVICEID_NOT_NULL = "deviceId cannot be null";
private static final String VIRTUALPORTID_NOT_NULL = "virtualPortId cannot be null";
private static final String HOST_NOT_NULL = "host cannot be null";
private static final String L3VNIMAP = "l3vniMap";
private static final String L3VNITENANTMAP = "l3vniTenantMap";
private static final String L3VNITENANTROUTERMAP = "l3vniTenantRouterMap";
private static final String CLASSIFIEROVSMAP = "classifierOvsMap";
private static final String SFFOVSMAP = "sffOvsMap";
......@@ -165,9 +168,15 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
.register(KryoNamespaces.API)
.register(TenantId.class, DeviceId.class, SegmentationId.class);
l3vniMap = storageService
l3vniTenantMap = storageService
.<TenantId, SegmentationId>eventuallyConsistentMapBuilder()
.withName(L3VNIMAP).withSerializer(serializer)
.withName(L3VNITENANTMAP).withSerializer(serializer)
.withTimestampProvider((k, v) -> clockService.getTimestamp())
.build();
l3vniTenantRouterMap = storageService
.<TenantRouter, SegmentationId>eventuallyConsistentMapBuilder()
.withName(L3VNITENANTROUTERMAP).withSerializer(serializer)
.withTimestampProvider((k, v) -> clockService.getTimestamp())
.build();
......@@ -195,7 +204,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
flowClassifierService.removeListener(flowClassifierListener);
portChainService.removeListener(portChainListener);
l3vniMap.destroy();
l3vniTenantMap.destroy();
l3vniTenantRouterMap.destroy();
classifierOvsMap.destroy();
sffOvsMap.destroy();
log.info("Stopped");
......@@ -204,13 +214,27 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
@Override
public SegmentationId getL3vni(TenantId tenantId) {
checkNotNull(tenantId, "tenantId cannot be null");
SegmentationId l3vni = l3vniMap.get(tenantId);
SegmentationId l3vni = l3vniTenantMap.get(tenantId);
if (l3vni == null) {
long segmentationId = coreService.getIdGenerator(RUNNELOPTOPOIC)
.getNewId();
l3vni = SegmentationId.segmentationId(String
.valueOf(segmentationId));
l3vniTenantMap.put(tenantId, l3vni);
}
return l3vni;
}
@Override
public SegmentationId getL3vni(TenantRouter tenantRouter) {
checkNotNull(tenantRouter, "tenantRouter cannot be null");
SegmentationId l3vni = l3vniTenantRouterMap.get(tenantRouter);
if (l3vni == null) {
long segmentationId = coreService.getIdGenerator(RUNNELOPTOPOIC)
.getNewId();
l3vni = SegmentationId.segmentationId(String
.valueOf(segmentationId));
l3vniMap.put(tenantId, l3vni);
l3vniTenantRouterMap.put(tenantRouter, l3vni);
}
return l3vni;
}
......