[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
Showing
5 changed files
with
174 additions
and
29 deletions
... | @@ -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 | } | ... | ... |
... | @@ -110,6 +110,7 @@ import org.onosproject.vtnrsc.SubnetId; | ... | @@ -110,6 +110,7 @@ import org.onosproject.vtnrsc.SubnetId; |
110 | import org.onosproject.vtnrsc.TenantId; | 110 | import org.onosproject.vtnrsc.TenantId; |
111 | import org.onosproject.vtnrsc.TenantNetwork; | 111 | import org.onosproject.vtnrsc.TenantNetwork; |
112 | import org.onosproject.vtnrsc.TenantNetworkId; | 112 | import org.onosproject.vtnrsc.TenantNetworkId; |
113 | +import org.onosproject.vtnrsc.TenantRouter; | ||
113 | import org.onosproject.vtnrsc.VirtualPort; | 114 | import org.onosproject.vtnrsc.VirtualPort; |
114 | import org.onosproject.vtnrsc.VirtualPortId; | 115 | import org.onosproject.vtnrsc.VirtualPortId; |
115 | import org.onosproject.vtnrsc.event.VtnRscEvent; | 116 | import org.onosproject.vtnrsc.event.VtnRscEvent; |
... | @@ -199,7 +200,7 @@ public class VtnManager implements VtnService { | ... | @@ -199,7 +200,7 @@ public class VtnManager implements VtnService { |
199 | private static final String VIRTUALPORT = "vtn-virtual-port"; | 200 | private static final String VIRTUALPORT = "vtn-virtual-port"; |
200 | private static final String SWITCHES_OF_CONTROLLER = "switchesOfController"; | 201 | private static final String SWITCHES_OF_CONTROLLER = "switchesOfController"; |
201 | private static final String SWITCH_OF_LOCAL_HOST_PORTS = "switchOfLocalHostPorts"; | 202 | private static final String SWITCH_OF_LOCAL_HOST_PORTS = "switchOfLocalHostPorts"; |
202 | - private static final String ROUTERINF_FLAG_OF_TENANT = "routerInfFlagOfTenant"; | 203 | + private static final String ROUTERINF_FLAG_OF_TENANTROUTER = "routerInfFlagOfTenantRouter"; |
203 | private static final String HOSTS_OF_SUBNET = "hostsOfSubnet"; | 204 | private static final String HOSTS_OF_SUBNET = "hostsOfSubnet"; |
204 | private static final String EX_PORT_OF_DEVICE = "exPortOfDevice"; | 205 | private static final String EX_PORT_OF_DEVICE = "exPortOfDevice"; |
205 | private static final String EX_PORT_MAP = "exPortMap"; | 206 | private static final String EX_PORT_MAP = "exPortMap"; |
... | @@ -210,7 +211,7 @@ public class VtnManager implements VtnService { | ... | @@ -210,7 +211,7 @@ public class VtnManager implements VtnService { |
210 | private EventuallyConsistentMap<IpAddress, Boolean> switchesOfController; | 211 | private EventuallyConsistentMap<IpAddress, Boolean> switchesOfController; |
211 | private EventuallyConsistentMap<DeviceId, NetworkOfLocalHostPorts> switchOfLocalHostPorts; | 212 | private EventuallyConsistentMap<DeviceId, NetworkOfLocalHostPorts> switchOfLocalHostPorts; |
212 | private EventuallyConsistentMap<SubnetId, Map<HostId, Host>> hostsOfSubnet; | 213 | private EventuallyConsistentMap<SubnetId, Map<HostId, Host>> hostsOfSubnet; |
213 | - private EventuallyConsistentMap<TenantId, Boolean> routerInfFlagOfTenant; | 214 | + private EventuallyConsistentMap<TenantRouter, Boolean> routerInfFlagOfTenantRouter; |
214 | private EventuallyConsistentMap<DeviceId, Port> exPortOfDevice; | 215 | private EventuallyConsistentMap<DeviceId, Port> exPortOfDevice; |
215 | private static ConsistentMap<String, String> exPortMap; | 216 | private static ConsistentMap<String, String> exPortMap; |
216 | 217 | ||
... | @@ -269,9 +270,9 @@ public class VtnManager implements VtnService { | ... | @@ -269,9 +270,9 @@ public class VtnManager implements VtnService { |
269 | .withTimestampProvider((k, v) -> clockService.getTimestamp()) | 270 | .withTimestampProvider((k, v) -> clockService.getTimestamp()) |
270 | .build(); | 271 | .build(); |
271 | 272 | ||
272 | - routerInfFlagOfTenant = storageService | 273 | + routerInfFlagOfTenantRouter = storageService |
273 | - .<TenantId, Boolean>eventuallyConsistentMapBuilder() | 274 | + .<TenantRouter, Boolean>eventuallyConsistentMapBuilder() |
274 | - .withName(ROUTERINF_FLAG_OF_TENANT).withSerializer(serializer) | 275 | + .withName(ROUTERINF_FLAG_OF_TENANTROUTER).withSerializer(serializer) |
275 | .withTimestampProvider((k, v) -> clockService.getTimestamp()) | 276 | .withTimestampProvider((k, v) -> clockService.getTimestamp()) |
276 | .build(); | 277 | .build(); |
277 | 278 | ||
... | @@ -766,10 +767,13 @@ public class VtnManager implements VtnService { | ... | @@ -766,10 +767,13 @@ public class VtnManager implements VtnService { |
766 | vPortStore.put(gwPort.portId(), gwPort); | 767 | vPortStore.put(gwPort.portId(), gwPort); |
767 | Iterable<RouterInterface> interfaces = routerInterfaceService | 768 | Iterable<RouterInterface> interfaces = routerInterfaceService |
768 | .getRouterInterfaces(); | 769 | .getRouterInterfaces(); |
769 | - Set<RouterInterface> interfacesSet = Sets.newHashSet(interfaces) | 770 | + Set<RouterInterface> interfacesSet = Sets.newHashSet(interfaces).stream() |
770 | - .stream().filter(r -> r.tenantId().equals(routerInf.tenantId())) | 771 | + .filter(r -> r.tenantId().equals(routerInf.tenantId())) |
772 | + .filter(r -> r.routerId().equals(routerInf.routerId())) | ||
771 | .collect(Collectors.toSet()); | 773 | .collect(Collectors.toSet()); |
772 | - if (routerInfFlagOfTenant.get(routerInf.tenantId()) != null) { | 774 | + TenantRouter tenantRouter = TenantRouter |
775 | + .tenantRouter(routerInf.tenantId(), routerInf.routerId()); | ||
776 | + if (routerInfFlagOfTenantRouter.get(tenantRouter) != null) { | ||
773 | programRouterInterface(routerInf, operation); | 777 | programRouterInterface(routerInf, operation); |
774 | } else { | 778 | } else { |
775 | if (interfacesSet.size() >= SUBNET_NUM) { | 779 | if (interfacesSet.size() >= SUBNET_NUM) { |
... | @@ -787,10 +791,12 @@ public class VtnManager implements VtnService { | ... | @@ -787,10 +791,12 @@ public class VtnManager implements VtnService { |
787 | Set<RouterInterface> interfacesSet = Sets.newHashSet(interfaces) | 791 | Set<RouterInterface> interfacesSet = Sets.newHashSet(interfaces) |
788 | .stream().filter(r -> r.tenantId().equals(routerInf.tenantId())) | 792 | .stream().filter(r -> r.tenantId().equals(routerInf.tenantId())) |
789 | .collect(Collectors.toSet()); | 793 | .collect(Collectors.toSet()); |
790 | - if (routerInfFlagOfTenant.get(routerInf.tenantId()) != null) { | 794 | + TenantRouter tenantRouter = TenantRouter |
795 | + .tenantRouter(routerInf.tenantId(), routerInf.routerId()); | ||
796 | + if (routerInfFlagOfTenantRouter.get(tenantRouter) != null) { | ||
791 | programRouterInterface(routerInf, operation); | 797 | programRouterInterface(routerInf, operation); |
792 | if (interfacesSet.size() == 1) { | 798 | if (interfacesSet.size() == 1) { |
793 | - routerInfFlagOfTenant.remove(routerInf.tenantId()); | 799 | + routerInfFlagOfTenantRouter.remove(tenantRouter); |
794 | interfacesSet.stream().forEach(r -> { | 800 | interfacesSet.stream().forEach(r -> { |
795 | programRouterInterface(r, operation); | 801 | programRouterInterface(r, operation); |
796 | }); | 802 | }); |
... | @@ -822,7 +828,9 @@ public class VtnManager implements VtnService { | ... | @@ -822,7 +828,9 @@ public class VtnManager implements VtnService { |
822 | if (hosts != null && hosts.size() > 0) { | 828 | if (hosts != null && hosts.size() > 0) { |
823 | subnetVmNum++; | 829 | subnetVmNum++; |
824 | if (subnetVmNum >= SUBNET_NUM) { | 830 | if (subnetVmNum >= SUBNET_NUM) { |
825 | - routerInfFlagOfTenant.put(r.tenantId(), true); | 831 | + TenantRouter tenantRouter = TenantRouter |
832 | + .tenantRouter(r.tenantId(), r.routerId()); | ||
833 | + routerInfFlagOfTenantRouter.put(tenantRouter, true); | ||
826 | interfacesSet.stream().forEach(f -> { | 834 | interfacesSet.stream().forEach(f -> { |
827 | programRouterInterface(f, operation); | 835 | programRouterInterface(f, operation); |
828 | }); | 836 | }); |
... | @@ -834,7 +842,9 @@ public class VtnManager implements VtnService { | ... | @@ -834,7 +842,9 @@ public class VtnManager implements VtnService { |
834 | 842 | ||
835 | private void programRouterInterface(RouterInterface routerInf, | 843 | private void programRouterInterface(RouterInterface routerInf, |
836 | Objective.Operation operation) { | 844 | Objective.Operation operation) { |
837 | - SegmentationId l3vni = vtnRscService.getL3vni(routerInf.tenantId()); | 845 | + TenantRouter tenantRouter = TenantRouter |
846 | + .tenantRouter(routerInf.tenantId(), routerInf.routerId()); | ||
847 | + SegmentationId l3vni = vtnRscService.getL3vni(tenantRouter); | ||
838 | // Get all the host of the subnet | 848 | // Get all the host of the subnet |
839 | Map<HostId, Host> hosts = hostsOfSubnet.get(routerInf.subnetId()); | 849 | Map<HostId, Host> hosts = hostsOfSubnet.get(routerInf.subnetId()); |
840 | hosts.values().stream().forEach(h -> { | 850 | hosts.values().stream().forEach(h -> { |
... | @@ -929,8 +939,9 @@ public class VtnManager implements VtnService { | ... | @@ -929,8 +939,9 @@ public class VtnManager implements VtnService { |
929 | if (host != null && vmPort != null && fipPort != null) { | 939 | if (host != null && vmPort != null && fipPort != null) { |
930 | DeviceId deviceId = host.location().deviceId(); | 940 | DeviceId deviceId = host.location().deviceId(); |
931 | Port exPort = exPortOfDevice.get(deviceId); | 941 | Port exPort = exPortOfDevice.get(deviceId); |
932 | - SegmentationId l3vni = vtnRscService | 942 | + TenantRouter tenantRouter = TenantRouter |
933 | - .getL3vni(vmPort.tenantId()); | 943 | + .tenantRouter(floaingIp.tenantId(), floaingIp.routerId()); |
944 | + SegmentationId l3vni = vtnRscService.getL3vni(tenantRouter); | ||
934 | // Floating ip BIND | 945 | // Floating ip BIND |
935 | if (type == VtnRscEvent.Type.FLOATINGIP_BIND) { | 946 | if (type == VtnRscEvent.Type.FLOATINGIP_BIND) { |
936 | vPortStore.put(fipPort.portId(), fipPort); | 947 | vPortStore.put(fipPort.portId(), fipPort); |
... | @@ -951,7 +962,7 @@ public class VtnManager implements VtnService { | ... | @@ -951,7 +962,7 @@ public class VtnManager implements VtnService { |
951 | private void applyNorthSouthL3Flows(DeviceId deviceId, Host host, | 962 | private void applyNorthSouthL3Flows(DeviceId deviceId, Host host, |
952 | VirtualPort vmPort, VirtualPort fipPort, | 963 | VirtualPort vmPort, VirtualPort fipPort, |
953 | FloatingIp floatingIp, | 964 | FloatingIp floatingIp, |
954 | - SegmentationId l3Vni, Port exPort, | 965 | + SegmentationId l3vni, Port exPort, |
955 | Objective.Operation operation) { | 966 | Objective.Operation operation) { |
956 | if (!mastershipService.isLocalMaster(deviceId)) { | 967 | if (!mastershipService.isLocalMaster(deviceId)) { |
957 | log.debug("not master device:{}", deviceId); | 968 | log.debug("not master device:{}", deviceId); |
... | @@ -980,9 +991,9 @@ public class VtnManager implements VtnService { | ... | @@ -980,9 +991,9 @@ public class VtnManager implements VtnService { |
980 | operation); | 991 | operation); |
981 | dnatService.programRules(deviceId, floatingIp.floatingIp(), | 992 | dnatService.programRules(deviceId, floatingIp.floatingIp(), |
982 | fGwMac, floatingIp.fixedIp(), | 993 | fGwMac, floatingIp.fixedIp(), |
983 | - l3Vni, operation); | 994 | + l3vni, operation); |
984 | l3ForwardService | 995 | l3ForwardService |
985 | - .programRouteRules(deviceId, l3Vni, floatingIp.fixedIp(), | 996 | + .programRouteRules(deviceId, l3vni, floatingIp.fixedIp(), |
986 | vmNetwork.segmentationId(), dstVmGwMac, | 997 | vmNetwork.segmentationId(), dstVmGwMac, |
987 | vmPort.macAddress(), operation); | 998 | vmPort.macAddress(), operation); |
988 | 999 | ||
... | @@ -990,8 +1001,8 @@ public class VtnManager implements VtnService { | ... | @@ -990,8 +1001,8 @@ public class VtnManager implements VtnService { |
990 | classifierService.programL3InPortClassifierRules(deviceId, | 1001 | classifierService.programL3InPortClassifierRules(deviceId, |
991 | host.location().port(), | 1002 | host.location().port(), |
992 | host.mac(), dstVmGwMac, | 1003 | host.mac(), dstVmGwMac, |
993 | - l3Vni, operation); | 1004 | + l3vni, operation); |
994 | - snatService.programRules(deviceId, l3Vni, floatingIp.fixedIp(), | 1005 | + snatService.programRules(deviceId, l3vni, floatingIp.fixedIp(), |
995 | fGwMac, exPortMac, | 1006 | fGwMac, exPortMac, |
996 | floatingIp.floatingIp(), | 1007 | floatingIp.floatingIp(), |
997 | fipNetwork.segmentationId(), operation); | 1008 | fipNetwork.segmentationId(), operation); |
... | @@ -1056,7 +1067,6 @@ public class VtnManager implements VtnService { | ... | @@ -1056,7 +1067,6 @@ public class VtnManager implements VtnService { |
1056 | } | 1067 | } |
1057 | TenantId tenantId = port.tenantId(); | 1068 | TenantId tenantId = port.tenantId(); |
1058 | Port exPort = exPortOfDevice.get(deviceId); | 1069 | Port exPort = exPortOfDevice.get(deviceId); |
1059 | - SegmentationId l3vni = vtnRscService.getL3vni(tenantId); | ||
1060 | Iterator<FixedIp> fixips = port.fixedIps().iterator(); | 1070 | Iterator<FixedIp> fixips = port.fixedIps().iterator(); |
1061 | SubnetId sid = null; | 1071 | SubnetId sid = null; |
1062 | IpAddress hostIp = null; | 1072 | IpAddress hostIp = null; |
... | @@ -1069,14 +1079,23 @@ public class VtnManager implements VtnService { | ... | @@ -1069,14 +1079,23 @@ public class VtnManager implements VtnService { |
1069 | // L3 internal network access to each other | 1079 | // L3 internal network access to each other |
1070 | Iterable<RouterInterface> interfaces = routerInterfaceService | 1080 | Iterable<RouterInterface> interfaces = routerInterfaceService |
1071 | .getRouterInterfaces(); | 1081 | .getRouterInterfaces(); |
1082 | + Set<RouterInterface> hostInterfaces = Sets.newHashSet(interfaces) | ||
1083 | + .stream().filter(r -> r.tenantId().equals(tenantId)) | ||
1084 | + .filter(r -> r.subnetId().equals(subnetId)) | ||
1085 | + .collect(Collectors.toSet()); | ||
1086 | + hostInterfaces.stream().forEach(routerInf -> { | ||
1072 | Set<RouterInterface> interfacesSet = Sets.newHashSet(interfaces) | 1087 | Set<RouterInterface> interfacesSet = Sets.newHashSet(interfaces) |
1073 | .stream().filter(r -> r.tenantId().equals(tenantId)) | 1088 | .stream().filter(r -> r.tenantId().equals(tenantId)) |
1089 | + .filter(r -> r.routerId().equals(routerInf.routerId())) | ||
1074 | .collect(Collectors.toSet()); | 1090 | .collect(Collectors.toSet()); |
1075 | long count = interfacesSet.stream() | 1091 | long count = interfacesSet.stream() |
1076 | .filter(r -> !r.subnetId().equals(subnetId)).count(); | 1092 | .filter(r -> !r.subnetId().equals(subnetId)).count(); |
1077 | if (count > 0) { | 1093 | if (count > 0) { |
1094 | + TenantRouter tenantRouter = TenantRouter | ||
1095 | + .tenantRouter(routerInf.tenantId(), routerInf.routerId()); | ||
1096 | + SegmentationId l3vni = vtnRscService.getL3vni(tenantRouter); | ||
1078 | if (operation == Objective.Operation.ADD) { | 1097 | if (operation == Objective.Operation.ADD) { |
1079 | - if (routerInfFlagOfTenant.get(tenantId) != null) { | 1098 | + if (routerInfFlagOfTenantRouter.get(tenantRouter) != null) { |
1080 | applyEastWestL3Flows(host, l3vni, operation); | 1099 | applyEastWestL3Flows(host, l3vni, operation); |
1081 | } else { | 1100 | } else { |
1082 | if (interfacesSet.size() > 1) { | 1101 | if (interfacesSet.size() > 1) { |
... | @@ -1084,11 +1103,12 @@ public class VtnManager implements VtnService { | ... | @@ -1084,11 +1103,12 @@ public class VtnManager implements VtnService { |
1084 | } | 1103 | } |
1085 | } | 1104 | } |
1086 | } else if (operation == Objective.Operation.REMOVE) { | 1105 | } else if (operation == Objective.Operation.REMOVE) { |
1087 | - if (routerInfFlagOfTenant.get(tenantId) != null) { | 1106 | + if (routerInfFlagOfTenantRouter.get(tenantRouter) != null) { |
1088 | applyEastWestL3Flows(host, l3vni, operation); | 1107 | applyEastWestL3Flows(host, l3vni, operation); |
1089 | } | 1108 | } |
1090 | } | 1109 | } |
1091 | } | 1110 | } |
1111 | + }); | ||
1092 | // L3 external and internal network access to each other | 1112 | // L3 external and internal network access to each other |
1093 | FloatingIp floatingIp = null; | 1113 | FloatingIp floatingIp = null; |
1094 | Iterable<FloatingIp> floatingIps = floatingIpService.getFloatingIps(); | 1114 | Iterable<FloatingIp> floatingIps = floatingIpService.getFloatingIps(); |
... | @@ -1103,6 +1123,9 @@ public class VtnManager implements VtnService { | ... | @@ -1103,6 +1123,9 @@ public class VtnManager implements VtnService { |
1103 | } | 1123 | } |
1104 | } | 1124 | } |
1105 | if (floatingIp != null) { | 1125 | if (floatingIp != null) { |
1126 | + TenantRouter tenantRouter = TenantRouter | ||
1127 | + .tenantRouter(floatingIp.tenantId(), floatingIp.routerId()); | ||
1128 | + SegmentationId l3vni = vtnRscService.getL3vni(tenantRouter); | ||
1106 | VirtualPort fipPort = virtualPortService | 1129 | VirtualPort fipPort = virtualPortService |
1107 | .getPort(floatingIp.networkId(), floatingIp.floatingIp()); | 1130 | .getPort(floatingIp.networkId(), floatingIp.floatingIp()); |
1108 | if (fipPort == null) { | 1131 | if (fipPort == null) { | ... | ... |
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 | } | ... | ... |
-
Please register or login to post a comment