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; ...@@ -24,6 +24,7 @@ import org.onosproject.net.Host;
24 import org.onosproject.net.HostId; 24 import org.onosproject.net.HostId;
25 import org.onosproject.vtnrsc.SegmentationId; 25 import org.onosproject.vtnrsc.SegmentationId;
26 import org.onosproject.vtnrsc.TenantId; 26 import org.onosproject.vtnrsc.TenantId;
27 +import org.onosproject.vtnrsc.TenantRouter;
27 import org.onosproject.vtnrsc.VirtualPortId; 28 import org.onosproject.vtnrsc.VirtualPortId;
28 import org.onosproject.vtnrsc.event.VtnRscListener; 29 import org.onosproject.vtnrsc.event.VtnRscListener;
29 import org.onosproject.vtnrsc.service.VtnRscService; 30 import org.onosproject.vtnrsc.service.VtnRscService;
...@@ -79,4 +80,9 @@ public class VtnRscAdapter implements VtnRscService { ...@@ -79,4 +80,9 @@ public class VtnRscAdapter implements VtnRscService {
79 public void removeDeviceIdOfOvsMap(Host host, TenantId tenantId, 80 public void removeDeviceIdOfOvsMap(Host host, TenantId tenantId,
80 DeviceId deviceId) { 81 DeviceId deviceId) {
81 } 82 }
83 +
84 + @Override
85 + public SegmentationId getL3vni(TenantRouter tenantRouter) {
86 + return null;
87 + }
82 } 88 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.vtnrsc;
17 +
18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 +import static com.google.common.base.Preconditions.checkNotNull;
20 +
21 +import java.util.Objects;
22 +
23 +public final class TenantRouter {
24 + private final TenantId tenantId;
25 + private final RouterId routerId;
26 +
27 + /**
28 + * Construct a TenantRouter object.
29 + *
30 + * @param tenantId the tenant identifier
31 + * @param routerId router identifier
32 + */
33 + private TenantRouter(TenantId tenantId, RouterId routerId) {
34 + this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
35 + this.routerId = checkNotNull(routerId, "routerId cannot be null");
36 + }
37 +
38 + /**
39 + * Create a TenantRouter object.
40 + *
41 + * @param tenantId the tenant identifier
42 + * @param routerId router identifier
43 + * @return TenantRouter
44 + */
45 + public static TenantRouter tenantRouter(TenantId tenantId, RouterId routerId) {
46 + return new TenantRouter(tenantId, routerId);
47 + }
48 +
49 + public TenantId tenantId() {
50 + return tenantId;
51 + }
52 +
53 + public RouterId routerId() {
54 + return routerId;
55 + }
56 +
57 + @Override
58 + public int hashCode() {
59 + return Objects.hash(tenantId, routerId);
60 + }
61 +
62 + @Override
63 + public boolean equals(Object obj) {
64 + if (this == obj) {
65 + return true;
66 + }
67 + if (obj instanceof TenantRouter) {
68 + final TenantRouter that = (TenantRouter) obj;
69 + return this.getClass() == that.getClass()
70 + && Objects.equals(this.tenantId, that.tenantId)
71 + && Objects.equals(this.routerId, that.routerId);
72 + }
73 + return false;
74 + }
75 +
76 + @Override
77 + public String toString() {
78 + return toStringHelper(this)
79 + .add("tenantId", tenantId)
80 + .add("routerId", routerId)
81 + .toString();
82 + }
83 +}
...@@ -23,6 +23,7 @@ import org.onosproject.net.Host; ...@@ -23,6 +23,7 @@ import org.onosproject.net.Host;
23 import org.onosproject.net.HostId; 23 import org.onosproject.net.HostId;
24 import org.onosproject.vtnrsc.SegmentationId; 24 import org.onosproject.vtnrsc.SegmentationId;
25 import org.onosproject.vtnrsc.TenantId; 25 import org.onosproject.vtnrsc.TenantId;
26 +import org.onosproject.vtnrsc.TenantRouter;
26 import org.onosproject.vtnrsc.VirtualPortId; 27 import org.onosproject.vtnrsc.VirtualPortId;
27 import org.onosproject.vtnrsc.event.VtnRscEvent; 28 import org.onosproject.vtnrsc.event.VtnRscEvent;
28 import org.onosproject.vtnrsc.event.VtnRscListener; 29 import org.onosproject.vtnrsc.event.VtnRscListener;
...@@ -42,6 +43,14 @@ public interface VtnRscService extends ListenerService<VtnRscEvent, VtnRscListen ...@@ -42,6 +43,14 @@ public interface VtnRscService extends ListenerService<VtnRscEvent, VtnRscListen
42 SegmentationId getL3vni(TenantId tenantId); 43 SegmentationId getL3vni(TenantId tenantId);
43 44
44 /** 45 /**
46 + * Returns the SegmentationId of tenantRouter.
47 + *
48 + * @param tenantRouter TenantRouter
49 + * @return SegmentationId the SegmentationId of tenantRouter
50 + */
51 + SegmentationId getL3vni(TenantRouter tenantRouter);
52 +
53 + /**
45 * Returns Classifier Ovs list of the specific tenant. 54 * Returns Classifier Ovs list of the specific tenant.
46 * 55 *
47 * @param tenantId tenant identifier 56 * @param tenantId tenant identifier
......
...@@ -56,6 +56,7 @@ import org.onosproject.vtnrsc.SegmentationId; ...@@ -56,6 +56,7 @@ import org.onosproject.vtnrsc.SegmentationId;
56 import org.onosproject.vtnrsc.Subnet; 56 import org.onosproject.vtnrsc.Subnet;
57 import org.onosproject.vtnrsc.SubnetId; 57 import org.onosproject.vtnrsc.SubnetId;
58 import org.onosproject.vtnrsc.TenantId; 58 import org.onosproject.vtnrsc.TenantId;
59 +import org.onosproject.vtnrsc.TenantRouter;
59 import org.onosproject.vtnrsc.VirtualPort; 60 import org.onosproject.vtnrsc.VirtualPort;
60 import org.onosproject.vtnrsc.VirtualPortId; 61 import org.onosproject.vtnrsc.VirtualPortId;
61 import org.onosproject.vtnrsc.event.VtnRscEvent; 62 import org.onosproject.vtnrsc.event.VtnRscEvent;
...@@ -111,7 +112,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi ...@@ -111,7 +112,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
111 private FlowClassifierListener flowClassifierListener = new InnerFlowClassifierListener(); 112 private FlowClassifierListener flowClassifierListener = new InnerFlowClassifierListener();
112 private PortChainListener portChainListener = new InnerPortChainListener(); 113 private PortChainListener portChainListener = new InnerPortChainListener();
113 114
114 - private EventuallyConsistentMap<TenantId, SegmentationId> l3vniMap; 115 + private EventuallyConsistentMap<TenantId, SegmentationId> l3vniTenantMap;
116 + private EventuallyConsistentMap<TenantRouter, SegmentationId> l3vniTenantRouterMap;
115 private EventuallyConsistentMap<TenantId, Set<DeviceId>> classifierOvsMap; 117 private EventuallyConsistentMap<TenantId, Set<DeviceId>> classifierOvsMap;
116 private EventuallyConsistentMap<TenantId, Set<DeviceId>> sffOvsMap; 118 private EventuallyConsistentMap<TenantId, Set<DeviceId>> sffOvsMap;
117 119
...@@ -122,7 +124,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi ...@@ -122,7 +124,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
122 private static final String DEVICEID_NOT_NULL = "deviceId cannot be null"; 124 private static final String DEVICEID_NOT_NULL = "deviceId cannot be null";
123 private static final String VIRTUALPORTID_NOT_NULL = "virtualPortId cannot be null"; 125 private static final String VIRTUALPORTID_NOT_NULL = "virtualPortId cannot be null";
124 private static final String HOST_NOT_NULL = "host cannot be null"; 126 private static final String HOST_NOT_NULL = "host cannot be null";
125 - private static final String L3VNIMAP = "l3vniMap"; 127 + private static final String L3VNITENANTMAP = "l3vniTenantMap";
128 + private static final String L3VNITENANTROUTERMAP = "l3vniTenantRouterMap";
126 private static final String CLASSIFIEROVSMAP = "classifierOvsMap"; 129 private static final String CLASSIFIEROVSMAP = "classifierOvsMap";
127 private static final String SFFOVSMAP = "sffOvsMap"; 130 private static final String SFFOVSMAP = "sffOvsMap";
128 131
...@@ -165,9 +168,15 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi ...@@ -165,9 +168,15 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
165 KryoNamespace.Builder serializer = KryoNamespace.newBuilder() 168 KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
166 .register(KryoNamespaces.API) 169 .register(KryoNamespaces.API)
167 .register(TenantId.class, DeviceId.class, SegmentationId.class); 170 .register(TenantId.class, DeviceId.class, SegmentationId.class);
168 - l3vniMap = storageService 171 + l3vniTenantMap = storageService
169 .<TenantId, SegmentationId>eventuallyConsistentMapBuilder() 172 .<TenantId, SegmentationId>eventuallyConsistentMapBuilder()
170 - .withName(L3VNIMAP).withSerializer(serializer) 173 + .withName(L3VNITENANTMAP).withSerializer(serializer)
174 + .withTimestampProvider((k, v) -> clockService.getTimestamp())
175 + .build();
176 +
177 + l3vniTenantRouterMap = storageService
178 + .<TenantRouter, SegmentationId>eventuallyConsistentMapBuilder()
179 + .withName(L3VNITENANTROUTERMAP).withSerializer(serializer)
171 .withTimestampProvider((k, v) -> clockService.getTimestamp()) 180 .withTimestampProvider((k, v) -> clockService.getTimestamp())
172 .build(); 181 .build();
173 182
...@@ -195,7 +204,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi ...@@ -195,7 +204,8 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
195 flowClassifierService.removeListener(flowClassifierListener); 204 flowClassifierService.removeListener(flowClassifierListener);
196 portChainService.removeListener(portChainListener); 205 portChainService.removeListener(portChainListener);
197 206
198 - l3vniMap.destroy(); 207 + l3vniTenantMap.destroy();
208 + l3vniTenantRouterMap.destroy();
199 classifierOvsMap.destroy(); 209 classifierOvsMap.destroy();
200 sffOvsMap.destroy(); 210 sffOvsMap.destroy();
201 log.info("Stopped"); 211 log.info("Stopped");
...@@ -204,13 +214,27 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi ...@@ -204,13 +214,27 @@ public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscLi
204 @Override 214 @Override
205 public SegmentationId getL3vni(TenantId tenantId) { 215 public SegmentationId getL3vni(TenantId tenantId) {
206 checkNotNull(tenantId, "tenantId cannot be null"); 216 checkNotNull(tenantId, "tenantId cannot be null");
207 - SegmentationId l3vni = l3vniMap.get(tenantId); 217 + SegmentationId l3vni = l3vniTenantMap.get(tenantId);
218 + if (l3vni == null) {
219 + long segmentationId = coreService.getIdGenerator(RUNNELOPTOPOIC)
220 + .getNewId();
221 + l3vni = SegmentationId.segmentationId(String
222 + .valueOf(segmentationId));
223 + l3vniTenantMap.put(tenantId, l3vni);
224 + }
225 + return l3vni;
226 + }
227 +
228 + @Override
229 + public SegmentationId getL3vni(TenantRouter tenantRouter) {
230 + checkNotNull(tenantRouter, "tenantRouter cannot be null");
231 + SegmentationId l3vni = l3vniTenantRouterMap.get(tenantRouter);
208 if (l3vni == null) { 232 if (l3vni == null) {
209 long segmentationId = coreService.getIdGenerator(RUNNELOPTOPOIC) 233 long segmentationId = coreService.getIdGenerator(RUNNELOPTOPOIC)
210 .getNewId(); 234 .getNewId();
211 l3vni = SegmentationId.segmentationId(String 235 l3vni = SegmentationId.segmentationId(String
212 .valueOf(segmentationId)); 236 .valueOf(segmentationId));
213 - l3vniMap.put(tenantId, l3vni); 237 + l3vniTenantRouterMap.put(tenantRouter, l3vni);
214 } 238 }
215 return l3vni; 239 return l3vni;
216 } 240 }
......