Committed by
Gerrit Code Review
[ONOS-4481] Integrate scalable gateway to openstackRouting
- Modified openstack_routing to use scalable gateway application - Add GatewayNode Builder method Change-Id: Ib12d52009eeb89ab59f01cafe794894aac80985e
Showing
10 changed files
with
125 additions
and
43 deletions
... | @@ -3,6 +3,7 @@ COMPILE_DEPS = [ | ... | @@ -3,6 +3,7 @@ COMPILE_DEPS = [ |
3 | '//core/store/serializers:onos-core-serializers', | 3 | '//core/store/serializers:onos-core-serializers', |
4 | '//apps/openstackinterface/api:onos-apps-openstackinterface-api', | 4 | '//apps/openstackinterface/api:onos-apps-openstackinterface-api', |
5 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', | 5 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', |
6 | + '//apps/scalablegateway:onos-apps-scalablegateway', | ||
6 | ] | 7 | ] |
7 | 8 | ||
8 | BUNDLES = [ | 9 | BUNDLES = [ | ... | ... |
... | @@ -52,6 +52,11 @@ | ... | @@ -52,6 +52,11 @@ |
52 | <artifactId>onos-app-openstackinterface-api</artifactId> | 52 | <artifactId>onos-app-openstackinterface-api</artifactId> |
53 | <version>${project.version}</version> | 53 | <version>${project.version}</version> |
54 | </dependency> | 54 | </dependency> |
55 | + <dependency> | ||
56 | + <groupId>org.onosproject</groupId> | ||
57 | + <artifactId>onos-scalablegateway</artifactId> | ||
58 | + <version>${project.version}</version> | ||
59 | + </dependency> | ||
55 | </dependencies> | 60 | </dependencies> |
56 | </project> | 61 | </project> |
57 | 62 | ... | ... |
... | @@ -40,6 +40,7 @@ import org.onosproject.openstackinterface.OpenstackPort; | ... | @@ -40,6 +40,7 @@ import org.onosproject.openstackinterface.OpenstackPort; |
40 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | 40 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; |
41 | import org.onosproject.openstacknetworking.OpenstackPortInfo; | 41 | import org.onosproject.openstacknetworking.OpenstackPortInfo; |
42 | import org.onosproject.openstacknetworking.OpenstackSwitchingService; | 42 | import org.onosproject.openstacknetworking.OpenstackSwitchingService; |
43 | +import org.onosproject.scalablegateway.api.ScalableGatewayService; | ||
43 | import org.slf4j.Logger; | 44 | import org.slf4j.Logger; |
44 | 45 | ||
45 | import java.nio.ByteBuffer; | 46 | import java.nio.ByteBuffer; |
... | @@ -62,13 +63,14 @@ public class OpenstackIcmpHandler { | ... | @@ -62,13 +63,14 @@ public class OpenstackIcmpHandler { |
62 | private final Map<String, OpenstackPortInfo> icmpInfoMap = Maps.newHashMap(); | 63 | private final Map<String, OpenstackPortInfo> icmpInfoMap = Maps.newHashMap(); |
63 | private final OpenstackSwitchingService openstackSwitchingService; | 64 | private final OpenstackSwitchingService openstackSwitchingService; |
64 | private final OpenstackInterfaceService openstackService; | 65 | private final OpenstackInterfaceService openstackService; |
66 | + private final ScalableGatewayService gatewayService; | ||
65 | private final OpenstackNetworkingConfig config; | 67 | private final OpenstackNetworkingConfig config; |
66 | private static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); | 68 | private static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); |
67 | private static final String NETWORK_ROUTER_INTERFACE = "network:router_interface"; | 69 | private static final String NETWORK_ROUTER_INTERFACE = "network:router_interface"; |
68 | private static final String PORTNAME = "portName"; | 70 | private static final String PORTNAME = "portName"; |
69 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; | 71 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; |
70 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; | 72 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; |
71 | - | 73 | + private static final String EXTERNAL_NODE_NULL = "There is no external node about this deviceId []"; |
72 | /** | 74 | /** |
73 | * Default constructor. | 75 | * Default constructor. |
74 | * | 76 | * |
... | @@ -77,15 +79,17 @@ public class OpenstackIcmpHandler { | ... | @@ -77,15 +79,17 @@ public class OpenstackIcmpHandler { |
77 | * @param openstackService openstackInterface service | 79 | * @param openstackService openstackInterface service |
78 | * @param config openstackRoutingConfig | 80 | * @param config openstackRoutingConfig |
79 | * @param openstackSwitchingService openstackSwitching service | 81 | * @param openstackSwitchingService openstackSwitching service |
82 | + * @param gatewayService scalable gateway service | ||
80 | */ | 83 | */ |
81 | OpenstackIcmpHandler(PacketService packetService, DeviceService deviceService, | 84 | OpenstackIcmpHandler(PacketService packetService, DeviceService deviceService, |
82 | OpenstackInterfaceService openstackService, OpenstackNetworkingConfig config, | 85 | OpenstackInterfaceService openstackService, OpenstackNetworkingConfig config, |
83 | - OpenstackSwitchingService openstackSwitchingService) { | 86 | + OpenstackSwitchingService openstackSwitchingService, ScalableGatewayService gatewayService) { |
84 | this.packetService = packetService; | 87 | this.packetService = packetService; |
85 | this.deviceService = deviceService; | 88 | this.deviceService = deviceService; |
86 | this.openstackService = checkNotNull(openstackService); | 89 | this.openstackService = checkNotNull(openstackService); |
87 | this.config = checkNotNull(config); | 90 | this.config = checkNotNull(config); |
88 | this.openstackSwitchingService = checkNotNull(openstackSwitchingService); | 91 | this.openstackSwitchingService = checkNotNull(openstackSwitchingService); |
92 | + this.gatewayService = gatewayService; | ||
89 | } | 93 | } |
90 | 94 | ||
91 | /** | 95 | /** |
... | @@ -99,10 +103,13 @@ public class OpenstackIcmpHandler { | ... | @@ -99,10 +103,13 @@ public class OpenstackIcmpHandler { |
99 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) | 103 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) |
100 | .build(); | 104 | .build(); |
101 | 105 | ||
106 | + Map<DeviceId, PortNumber> externalInfoMap = getExternalInfo(); | ||
107 | + | ||
108 | + externalInfoMap.keySet().forEach(deviceId -> | ||
102 | packetService.requestPackets(icmpSelector, | 109 | packetService.requestPackets(icmpSelector, |
103 | PacketPriority.CONTROL, | 110 | PacketPriority.CONTROL, |
104 | appId, | 111 | appId, |
105 | - Optional.of(DeviceId.deviceId(config.gatewayBridgeId()))); | 112 | + Optional.of(deviceId))); |
106 | } | 113 | } |
107 | 114 | ||
108 | /** | 115 | /** |
... | @@ -223,14 +230,19 @@ public class OpenstackIcmpHandler { | ... | @@ -223,14 +230,19 @@ public class OpenstackIcmpHandler { |
223 | Ethernet icmpRequestEth = new Ethernet(); | 230 | Ethernet icmpRequestEth = new Ethernet(); |
224 | 231 | ||
225 | icmpRequestEth.setEtherType(Ethernet.TYPE_IPV4) | 232 | icmpRequestEth.setEtherType(Ethernet.TYPE_IPV4) |
226 | - .setSourceMACAddress(MacAddress.valueOf(config.gatewayExternalInterfaceMac())) | ||
227 | - .setDestinationMACAddress(MacAddress.valueOf(config.physicalRouterMac())) | ||
228 | .setPayload(icmpRequestIpv4); | 233 | .setPayload(icmpRequestIpv4); |
229 | 234 | ||
230 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 235 | + TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
231 | - .setOutput(getPortForAnnotationPortName(DeviceId.deviceId(config.gatewayBridgeId()), | 236 | + |
232 | - config.gatewayExternalInterfaceName())) | 237 | + Map<DeviceId, PortNumber> externalInforMap = getExternalInfo(); |
233 | - .build(); | 238 | + |
239 | + if (externalInforMap.size() == 0 || !externalInforMap.containsKey(deviceId)) { | ||
240 | + log.error(EXTERNAL_NODE_NULL, deviceId.toString()); | ||
241 | + return; | ||
242 | + } | ||
243 | + tBuilder.setOutput(externalInforMap.get(deviceId)); | ||
244 | + | ||
245 | + TrafficTreatment treatment = tBuilder.build(); | ||
234 | 246 | ||
235 | OutboundPacket packet = new DefaultOutboundPacket(deviceId, | 247 | OutboundPacket packet = new DefaultOutboundPacket(deviceId, |
236 | treatment, ByteBuffer.wrap(icmpRequestEth.serialize())); | 248 | treatment, ByteBuffer.wrap(icmpRequestEth.serialize())); |
... | @@ -323,4 +335,10 @@ public class OpenstackIcmpHandler { | ... | @@ -323,4 +335,10 @@ public class OpenstackIcmpHandler { |
323 | } | 335 | } |
324 | return true; | 336 | return true; |
325 | } | 337 | } |
338 | + private Map<DeviceId, PortNumber> getExternalInfo() { | ||
339 | + Map<DeviceId, PortNumber> externalInfoMap = Maps.newHashMap(); | ||
340 | + gatewayService.getGatewayDeviceIds().forEach(deviceId -> | ||
341 | + externalInfoMap.putIfAbsent(deviceId, gatewayService.getGatewayExternalPorts(deviceId).get(0))); | ||
342 | + return externalInfoMap; | ||
343 | + } | ||
326 | } | 344 | } | ... | ... |
... | @@ -30,10 +30,11 @@ import org.onosproject.net.packet.InboundPacket; | ... | @@ -30,10 +30,11 @@ import org.onosproject.net.packet.InboundPacket; |
30 | import org.onosproject.net.packet.PacketContext; | 30 | import org.onosproject.net.packet.PacketContext; |
31 | import org.onosproject.net.packet.PacketService; | 31 | import org.onosproject.net.packet.PacketService; |
32 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 32 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
33 | -import org.onosproject.openstackinterface.OpenstackNetwork; | ||
34 | import org.onosproject.openstackinterface.OpenstackPort; | 33 | import org.onosproject.openstackinterface.OpenstackPort; |
35 | import org.onosproject.openstackinterface.OpenstackRouter; | 34 | import org.onosproject.openstackinterface.OpenstackRouter; |
36 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | 35 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; |
36 | +import org.onosproject.scalablegateway.api.GatewayNode; | ||
37 | +import org.onosproject.scalablegateway.api.ScalableGatewayService; | ||
37 | import org.slf4j.Logger; | 38 | import org.slf4j.Logger; |
38 | import org.slf4j.LoggerFactory; | 39 | import org.slf4j.LoggerFactory; |
39 | 40 | ||
... | @@ -60,6 +61,7 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -60,6 +61,7 @@ public class OpenstackPnatHandler implements Runnable { |
60 | private OpenstackNetworkingConfig config; | 61 | private OpenstackNetworkingConfig config; |
61 | 62 | ||
62 | private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; | 63 | private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; |
64 | + private static final String EXTERNAL_PORT_NULL = "There is no external port in this deviceId []"; | ||
63 | 65 | ||
64 | OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context, | 66 | OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context, |
65 | int portNum, OpenstackPort openstackPort, Port port, OpenstackNetworkingConfig config) { | 67 | int portNum, OpenstackPort openstackPort, Port port, OpenstackNetworkingConfig config) { |
... | @@ -84,16 +86,17 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -84,16 +86,17 @@ public class OpenstackPnatHandler implements Runnable { |
84 | 86 | ||
85 | OpenstackRouter router = getOpenstackRouter(openstackPort); | 87 | OpenstackRouter router = getOpenstackRouter(openstackPort); |
86 | 88 | ||
89 | + MacAddress externalMac = MacAddress.NONE; | ||
90 | + MacAddress routerMac = MacAddress.NONE; | ||
91 | + | ||
87 | rulePopulator.populatePnatFlowRules(inboundPacket, openstackPort, portNum, | 92 | rulePopulator.populatePnatFlowRules(inboundPacket, openstackPort, portNum, |
88 | - getExternalIp(router), MacAddress.valueOf(config.gatewayExternalInterfaceMac()), | 93 | + getExternalIp(router), externalMac, routerMac); |
89 | - MacAddress.valueOf(config.physicalRouterMac())); | ||
90 | 94 | ||
91 | packetOut((Ethernet) ethernet.clone(), inboundPacket.receivedFrom().deviceId(), portNum, router); | 95 | packetOut((Ethernet) ethernet.clone(), inboundPacket.receivedFrom().deviceId(), portNum, router); |
92 | } | 96 | } |
93 | 97 | ||
94 | private OpenstackRouter getOpenstackRouter(OpenstackPort openstackPort) { | 98 | private OpenstackRouter getOpenstackRouter(OpenstackPort openstackPort) { |
95 | OpenstackInterfaceService networkingService = getService(OpenstackInterfaceService.class); | 99 | OpenstackInterfaceService networkingService = getService(OpenstackInterfaceService.class); |
96 | - OpenstackNetwork network = networkingService.network(openstackPort.networkId()); | ||
97 | 100 | ||
98 | OpenstackPort port = networkingService.ports() | 101 | OpenstackPort port = networkingService.ports() |
99 | .stream() | 102 | .stream() |
... | @@ -146,11 +149,16 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -146,11 +149,16 @@ public class OpenstackPnatHandler implements Runnable { |
146 | iPacket.resetChecksum(); | 149 | iPacket.resetChecksum(); |
147 | iPacket.setParent(ethernet); | 150 | iPacket.setParent(ethernet); |
148 | ethernet.setPayload(iPacket); | 151 | ethernet.setPayload(iPacket); |
149 | - ethernet.setSourceMACAddress(config.gatewayExternalInterfaceMac()) | 152 | + ScalableGatewayService gatewayService = getService(ScalableGatewayService.class); |
150 | - .setDestinationMACAddress(config.physicalRouterMac()); | 153 | + GatewayNode gatewayNode = gatewayService.getGatewayNode(deviceId); |
154 | + if (gatewayNode.getGatewayExternalInterfaceNames().size() == 0) { | ||
155 | + log.error(EXTERNAL_PORT_NULL, deviceId.toString()); | ||
156 | + return; | ||
157 | + } | ||
158 | + treatment.setOutput(gatewayService.getGatewayExternalPorts(deviceId).get(0)); | ||
159 | + | ||
151 | ethernet.resetChecksum(); | 160 | ethernet.resetChecksum(); |
152 | 161 | ||
153 | - treatment.setOutput(port.number()); | ||
154 | 162 | ||
155 | packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(), | 163 | packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(), |
156 | ByteBuffer.wrap(ethernet.serialize()))); | 164 | ByteBuffer.wrap(ethernet.serialize()))); | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstacknetworking.routing; | 16 | package org.onosproject.openstacknetworking.routing; |
17 | 17 | ||
18 | +import com.google.common.collect.Lists; | ||
18 | import org.onlab.packet.ARP; | 19 | import org.onlab.packet.ARP; |
19 | import org.onlab.packet.EthType; | 20 | import org.onlab.packet.EthType; |
20 | import org.onlab.packet.Ethernet; | 21 | import org.onlab.packet.Ethernet; |
... | @@ -34,9 +35,11 @@ import org.onosproject.net.packet.PacketService; | ... | @@ -34,9 +35,11 @@ import org.onosproject.net.packet.PacketService; |
34 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 35 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
35 | import org.onosproject.openstackinterface.OpenstackPort; | 36 | import org.onosproject.openstackinterface.OpenstackPort; |
36 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | 37 | import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; |
38 | +import org.onosproject.scalablegateway.api.ScalableGatewayService; | ||
37 | import org.slf4j.Logger; | 39 | import org.slf4j.Logger; |
38 | 40 | ||
39 | import java.nio.ByteBuffer; | 41 | import java.nio.ByteBuffer; |
42 | +import java.util.List; | ||
40 | import java.util.Optional; | 43 | import java.util.Optional; |
41 | 44 | ||
42 | import static com.google.common.base.Preconditions.checkNotNull; | 45 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -51,21 +54,23 @@ public class OpenstackRoutingArpHandler { | ... | @@ -51,21 +54,23 @@ public class OpenstackRoutingArpHandler { |
51 | private final PacketService packetService; | 54 | private final PacketService packetService; |
52 | private final OpenstackInterfaceService openstackService; | 55 | private final OpenstackInterfaceService openstackService; |
53 | private final OpenstackNetworkingConfig config; | 56 | private final OpenstackNetworkingConfig config; |
57 | + private final ScalableGatewayService gatewayService; | ||
54 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; | 58 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; |
55 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; | 59 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; |
56 | 60 | ||
57 | /** | 61 | /** |
58 | * Default constructor. | 62 | * Default constructor. |
59 | - * | ||
60 | * @param packetService packet service | 63 | * @param packetService packet service |
61 | * @param openstackService openstackInterface service | 64 | * @param openstackService openstackInterface service |
62 | * @param config openstackRoutingConfig | 65 | * @param config openstackRoutingConfig |
66 | + * @param gatewayService | ||
63 | */ | 67 | */ |
64 | OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService, | 68 | OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService, |
65 | - OpenstackNetworkingConfig config) { | 69 | + OpenstackNetworkingConfig config, ScalableGatewayService gatewayService) { |
66 | this.packetService = packetService; | 70 | this.packetService = packetService; |
67 | this.openstackService = checkNotNull(openstackService); | 71 | this.openstackService = checkNotNull(openstackService); |
68 | this.config = checkNotNull(config); | 72 | this.config = checkNotNull(config); |
73 | + this.gatewayService = gatewayService; | ||
69 | } | 74 | } |
70 | 75 | ||
71 | /** | 76 | /** |
... | @@ -79,10 +84,12 @@ public class OpenstackRoutingArpHandler { | ... | @@ -79,10 +84,12 @@ public class OpenstackRoutingArpHandler { |
79 | .matchEthType(EthType.EtherType.ARP.ethType().toShort()) | 84 | .matchEthType(EthType.EtherType.ARP.ethType().toShort()) |
80 | .build(); | 85 | .build(); |
81 | 86 | ||
87 | + getExternalInfo().forEach(deviceId -> | ||
82 | packetService.requestPackets(arpSelector, | 88 | packetService.requestPackets(arpSelector, |
83 | PacketPriority.CONTROL, | 89 | PacketPriority.CONTROL, |
84 | appId, | 90 | appId, |
85 | - Optional.of(DeviceId.deviceId(config.gatewayBridgeId()))); | 91 | + Optional.of(deviceId)) |
92 | + ); | ||
86 | } | 93 | } |
87 | 94 | ||
88 | /** | 95 | /** |
... | @@ -138,4 +145,10 @@ public class OpenstackRoutingArpHandler { | ... | @@ -138,4 +145,10 @@ public class OpenstackRoutingArpHandler { |
138 | } | 145 | } |
139 | return port.macAddress(); | 146 | return port.macAddress(); |
140 | } | 147 | } |
148 | + | ||
149 | + private List<DeviceId> getExternalInfo() { | ||
150 | + List<DeviceId> externalInfoList = Lists.newArrayList(); | ||
151 | + gatewayService.getGatewayDeviceIds().forEach(externalInfoList::add); | ||
152 | + return externalInfoList; | ||
153 | + } | ||
141 | } | 154 | } | ... | ... |
... | @@ -56,6 +56,7 @@ import org.onosproject.openstacknetworking.OpenstackPortInfo; | ... | @@ -56,6 +56,7 @@ import org.onosproject.openstacknetworking.OpenstackPortInfo; |
56 | import org.onosproject.openstacknetworking.OpenstackRoutingService; | 56 | import org.onosproject.openstacknetworking.OpenstackRoutingService; |
57 | import org.onosproject.openstacknetworking.OpenstackSubjectFactories; | 57 | import org.onosproject.openstacknetworking.OpenstackSubjectFactories; |
58 | import org.onosproject.openstacknetworking.OpenstackSwitchingService; | 58 | import org.onosproject.openstacknetworking.OpenstackSwitchingService; |
59 | +import org.onosproject.scalablegateway.api.ScalableGatewayService; | ||
59 | import org.onosproject.store.serializers.KryoNamespaces; | 60 | import org.onosproject.store.serializers.KryoNamespaces; |
60 | import org.onosproject.store.service.ConsistentMap; | 61 | import org.onosproject.store.service.ConsistentMap; |
61 | import org.onosproject.store.service.Serializer; | 62 | import org.onosproject.store.service.Serializer; |
... | @@ -113,6 +114,8 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -113,6 +114,8 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
113 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
114 | protected StorageService storageService; | 115 | protected StorageService storageService; |
115 | 116 | ||
117 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
118 | + protected ScalableGatewayService gatewayService; | ||
116 | 119 | ||
117 | private ApplicationId appId; | 120 | private ApplicationId appId; |
118 | private ConsistentMap<Integer, String> tpPortNumMap; // Map<PortNum, allocated VM`s Mac & destionation Ip address> | 121 | private ConsistentMap<Integer, String> tpPortNumMap; // Map<PortNum, allocated VM`s Mac & destionation Ip address> |
... | @@ -444,8 +447,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -444,8 +447,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
444 | 447 | ||
445 | if (context.isHandled()) { | 448 | if (context.isHandled()) { |
446 | return; | 449 | return; |
447 | - } else if (!context.inPacket().receivedFrom().deviceId().toString() | 450 | + } else if (!checkGatewayNode(context.inPacket().receivedFrom().deviceId())) { |
448 | - .equals(config.gatewayBridgeId())) { | ||
449 | return; | 451 | return; |
450 | } | 452 | } |
451 | 453 | ||
... | @@ -472,16 +474,19 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -472,16 +474,19 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
472 | } | 474 | } |
473 | default: | 475 | default: |
474 | int portNum = getPortNum(ethernet.getSourceMAC(), iPacket.getDestinationAddress()); | 476 | int portNum = getPortNum(ethernet.getSourceMAC(), iPacket.getDestinationAddress()); |
475 | - Optional<Port> port = | 477 | + DeviceId deviceId = pkt.receivedFrom().deviceId(); |
476 | - getExternalPort(pkt.receivedFrom().deviceId(), config.gatewayExternalInterfaceName()); | 478 | + Port port = null; |
477 | - if (port.isPresent()) { | 479 | + port = deviceService.getPort(deviceId, |
480 | + gatewayService.getGatewayExternalPorts(deviceId).get(0)); | ||
481 | + if (port != null) { | ||
478 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), | 482 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), |
479 | Ip4Address.valueOf(iPacket.getSourceAddress())); | 483 | Ip4Address.valueOf(iPacket.getSourceAddress())); |
480 | l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, | 484 | l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, |
481 | - portNum, openstackPort, port.get(), config)); | 485 | + portNum, openstackPort, port, config)); |
482 | } else { | 486 | } else { |
483 | log.warn("There`s no external interface"); | 487 | log.warn("There`s no external interface"); |
484 | } | 488 | } |
489 | + | ||
485 | break; | 490 | break; |
486 | } | 491 | } |
487 | } else if (ethernet.getEtherType() == Ethernet.TYPE_ARP) { | 492 | } else if (ethernet.getEtherType() == Ethernet.TYPE_ARP) { |
... | @@ -511,6 +516,10 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -511,6 +516,10 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
511 | 516 | ||
512 | } | 517 | } |
513 | 518 | ||
519 | + private boolean checkGatewayNode(DeviceId deviceId) { | ||
520 | + return gatewayService.getGatewayDeviceIds().contains(deviceId); | ||
521 | + } | ||
522 | + | ||
514 | private void clearPortNumMap() { | 523 | private void clearPortNumMap() { |
515 | tpPortNumMap.entrySet().forEach(e -> { | 524 | tpPortNumMap.entrySet().forEach(e -> { |
516 | if (System.currentTimeMillis() - e.getValue().creationTime() > PNAT_PORT_EXPIRE_TIME) { | 525 | if (System.currentTimeMillis() - e.getValue().creationTime() > PNAT_PORT_EXPIRE_TIME) { |
... | @@ -600,21 +609,12 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -600,21 +609,12 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
600 | return; | 609 | return; |
601 | } | 610 | } |
602 | 611 | ||
603 | - checkNotNull(config.physicalRouterMac()); | 612 | + rulePopulator = new OpenstackRoutingRulePopulator(appId, openstackService, flowObjectiveService, |
604 | - checkNotNull(config.gatewayBridgeId()); | 613 | + deviceService, driverService, config, gatewayService); |
605 | - checkNotNull(config.gatewayExternalInterfaceMac()); | ||
606 | - checkNotNull(config.gatewayExternalInterfaceName()); | ||
607 | - | ||
608 | - log.warn("Configured info: {}, {}, {}, {}", config.physicalRouterMac(), config.gatewayBridgeId(), | ||
609 | - config.gatewayExternalInterfaceMac(), config.gatewayExternalInterfaceName()); | ||
610 | - | ||
611 | - rulePopulator = new OpenstackRoutingRulePopulator(appId, | ||
612 | - openstackService, flowObjectiveService, deviceService, driverService, config); | ||
613 | - | ||
614 | openstackIcmpHandler = new OpenstackIcmpHandler(packetService, deviceService, | 614 | openstackIcmpHandler = new OpenstackIcmpHandler(packetService, deviceService, |
615 | - openstackService, config, openstackSwitchingService); | 615 | + openstackService, config, openstackSwitchingService, gatewayService); |
616 | - openstackArpHandler = new OpenstackRoutingArpHandler(packetService, openstackService, config); | 616 | + openstackArpHandler = new OpenstackRoutingArpHandler(packetService, openstackService, |
617 | - | 617 | + config, gatewayService); |
618 | openstackIcmpHandler.requestPacket(appId); | 618 | openstackIcmpHandler.requestPacket(appId); |
619 | openstackArpHandler.requestPacket(appId); | 619 | openstackArpHandler.requestPacket(appId); |
620 | 620 | ... | ... |
This diff is collapsed. Click to expand it.
apps/scalablegateway/network-cfg.json
0 → 100644
... | @@ -66,6 +66,15 @@ public final class GatewayNode { | ... | @@ -66,6 +66,15 @@ public final class GatewayNode { |
66 | } | 66 | } |
67 | 67 | ||
68 | /** | 68 | /** |
69 | + * Returns GatewayNode builder object. | ||
70 | + * | ||
71 | + * @return GatewayNode builder | ||
72 | + */ | ||
73 | + public static GatewayNode.Builder builder() { | ||
74 | + return new Builder(); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
69 | * GatewayNode Builder class. | 78 | * GatewayNode Builder class. |
70 | */ | 79 | */ |
71 | public static final class Builder { | 80 | public static final class Builder { | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.scalablegateway.api; | ... | @@ -17,6 +17,7 @@ package org.onosproject.scalablegateway.api; |
17 | 17 | ||
18 | 18 | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
21 | import com.google.common.collect.Sets; | 22 | import com.google.common.collect.Sets; |
22 | import org.onlab.packet.Ip4Address; | 23 | import org.onlab.packet.Ip4Address; |
... | @@ -28,9 +29,10 @@ import org.slf4j.Logger; | ... | @@ -28,9 +29,10 @@ import org.slf4j.Logger; |
28 | import java.util.Collections; | 29 | import java.util.Collections; |
29 | import java.util.List; | 30 | import java.util.List; |
30 | import java.util.Set; | 31 | import java.util.Set; |
32 | +import java.util.stream.StreamSupport; | ||
31 | 33 | ||
32 | -import static org.slf4j.LoggerFactory.getLogger; | ||
33 | import static org.onosproject.net.config.Config.FieldPresence.MANDATORY; | 34 | import static org.onosproject.net.config.Config.FieldPresence.MANDATORY; |
35 | +import static org.slf4j.LoggerFactory.getLogger; | ||
34 | 36 | ||
35 | /** | 37 | /** |
36 | * Configuration object for OpensatckNode service. | 38 | * Configuration object for OpensatckNode service. |
... | @@ -79,9 +81,21 @@ public class GatewayNodeConfig extends Config<ApplicationId> { | ... | @@ -79,9 +81,21 @@ public class GatewayNodeConfig extends Config<ApplicationId> { |
79 | 81 | ||
80 | @Override | 82 | @Override |
81 | public boolean isValid() { | 83 | public boolean isValid() { |
82 | - return hasOnlyFields(NODES, BRIDGE_ID, DATAPLANE_IP, EXTERNAL_INTERFACE_NAME) && | 84 | + JsonNode jsonNodes = object.get(NODES); |
83 | - isIpAddress(DATAPLANE_IP, MANDATORY) && isString(BRIDGE_ID, MANDATORY) && | 85 | + |
84 | - isString(EXTERNAL_INTERFACE_NAME, MANDATORY); | 86 | + if (jsonNodes == null) { |
87 | + return false; | ||
88 | + } | ||
89 | + | ||
90 | + return hasOnlyFields(NODES) | ||
91 | + && StreamSupport.stream(jsonNodes.spliterator(), false).allMatch(this::checkValid); | ||
92 | + } | ||
93 | + | ||
94 | + private boolean checkValid(JsonNode jsonNode) { | ||
95 | + ObjectNode objectNode = (ObjectNode) jsonNode; | ||
96 | + return isString(objectNode, BRIDGE_ID, MANDATORY) | ||
97 | + && isIpAddress(objectNode, DATAPLANE_IP, MANDATORY) | ||
98 | + && isString(objectNode, EXTERNAL_INTERFACE_NAME, MANDATORY); | ||
85 | } | 99 | } |
86 | 100 | ||
87 | } | 101 | } | ... | ... |
-
Please register or login to post a comment