Committed by
Gerrit Code Review
OpenstackRouting refactoring
- Replace OpenstackPortInfo with HostService - Replace OpenstackRoutingConfig with OpenstackNodeService (Remove OpenstackRoutingConfig) - Rebased with 10330 (existing_vm) - Added initialization process using OpenstackNodeListener Change-Id: If2ce8eb86d242a7180c9154e1a0f1668b266bf1c
Showing
17 changed files
with
452 additions
and
538 deletions
... | @@ -13,14 +13,15 @@ | ... | @@ -13,14 +13,15 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.openstacknetworking.switching; | 16 | +package org.onosproject.openstacknetworking; |
17 | 17 | ||
18 | import org.onlab.packet.Ip4Address; | 18 | import org.onlab.packet.Ip4Address; |
19 | import org.onlab.packet.Ip4Prefix; | 19 | import org.onlab.packet.Ip4Prefix; |
20 | import org.onlab.packet.IpPrefix; | 20 | import org.onlab.packet.IpPrefix; |
21 | +import org.onlab.packet.MacAddress; | ||
21 | 22 | ||
22 | /** | 23 | /** |
23 | - * Provides constants used in OpenStack node services. | 24 | + * Provides constants used in OpenStackSwitching. |
24 | */ | 25 | */ |
25 | public final class Constants { | 26 | public final class Constants { |
26 | 27 | ||
... | @@ -33,9 +34,11 @@ public final class Constants { | ... | @@ -33,9 +34,11 @@ public final class Constants { |
33 | public static final String PORTNAME_PREFIX_ROUTER = "qr-"; | 34 | public static final String PORTNAME_PREFIX_ROUTER = "qr-"; |
34 | public static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; | 35 | public static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; |
35 | 36 | ||
36 | - // TODO remove this | 37 | + public static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); |
37 | - public static final String ROUTER_INTERFACE = "network:router_interface"; | 38 | + |
38 | - public static final String DEVICE_OWNER_GATEWAY = "network:router_gateway"; | 39 | + // TODO: Please change these valuses following the way vrouter is implemented |
40 | + public static final MacAddress GW_EXT_INT_MAC = MacAddress.valueOf("56:e6:30:a6:8c:e5"); | ||
41 | + public static final MacAddress PHY_ROUTER_MAC = MacAddress.valueOf("00:00:00:00:01:01"); | ||
39 | 42 | ||
40 | public static final Ip4Address DNS_SERVER_IP = Ip4Address.valueOf("8.8.8.8"); | 43 | public static final Ip4Address DNS_SERVER_IP = Ip4Address.valueOf("8.8.8.8"); |
41 | public static final IpPrefix IP_PREFIX_ANY = Ip4Prefix.valueOf("0.0.0.0/0"); | 44 | public static final IpPrefix IP_PREFIX_ANY = Ip4Prefix.valueOf("0.0.0.0/0"); |
... | @@ -51,4 +54,5 @@ public final class Constants { | ... | @@ -51,4 +54,5 @@ public final class Constants { |
51 | public static final int SWITCHING_RULE_PRIORITY = 30000; | 54 | public static final int SWITCHING_RULE_PRIORITY = 30000; |
52 | public static final int TUNNELTAG_RULE_PRIORITY = 30000; | 55 | public static final int TUNNELTAG_RULE_PRIORITY = 30000; |
53 | public static final int ACL_RULE_PRIORITY = 30000; | 56 | public static final int ACL_RULE_PRIORITY = 30000; |
57 | + | ||
54 | } | 58 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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.openstacknetworking; | ||
17 | - | ||
18 | -import org.onlab.packet.Ip4Address; | ||
19 | -import org.onlab.packet.MacAddress; | ||
20 | -import org.onosproject.net.DeviceId; | ||
21 | - | ||
22 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | - | ||
24 | -/** | ||
25 | - * Contains OpenstackPort Information. | ||
26 | - */ | ||
27 | -// TODO remove this | ||
28 | -public final class OpenstackPortInfo { | ||
29 | - private final Ip4Address hostIp; | ||
30 | - private final MacAddress hostMac; | ||
31 | - private final DeviceId deviceId; | ||
32 | - private final long vni; | ||
33 | - private final Ip4Address gatewayIP; | ||
34 | - private final String networkId; | ||
35 | - | ||
36 | - /** | ||
37 | - * Returns OpenstackPortInfo reference. | ||
38 | - * | ||
39 | - * @param hostIp host IP address | ||
40 | - * @param hostMac host MAC address | ||
41 | - * @param deviceId device ID | ||
42 | - * @param vni tunnel ID | ||
43 | - * @param gatewayIP gateway IP address | ||
44 | - * @param networkId network identifier | ||
45 | - */ | ||
46 | - public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni, | ||
47 | - Ip4Address gatewayIP, String networkId) { | ||
48 | - this.hostIp = hostIp; | ||
49 | - this.hostMac = hostMac; | ||
50 | - this.deviceId = deviceId; | ||
51 | - this.vni = vni; | ||
52 | - this.gatewayIP = gatewayIP; | ||
53 | - this.networkId = networkId; | ||
54 | - } | ||
55 | - | ||
56 | - /** | ||
57 | - * Returns IP address of the port. | ||
58 | - * | ||
59 | - * @return IP address | ||
60 | - */ | ||
61 | - public Ip4Address ip() { | ||
62 | - return hostIp; | ||
63 | - } | ||
64 | - | ||
65 | - /** | ||
66 | - * Returns MAC address of the port. | ||
67 | - * | ||
68 | - * @return MAC address | ||
69 | - */ | ||
70 | - public MacAddress mac() { | ||
71 | - return hostMac; | ||
72 | - } | ||
73 | - | ||
74 | - /** | ||
75 | - * Returns device ID. | ||
76 | - * | ||
77 | - * @return device ID | ||
78 | - */ | ||
79 | - public DeviceId deviceId() { | ||
80 | - return deviceId; | ||
81 | - } | ||
82 | - | ||
83 | - /** | ||
84 | - * Returns tunnel ID. | ||
85 | - * | ||
86 | - * @return tunnel ID | ||
87 | - */ | ||
88 | - public long vni() { | ||
89 | - return vni; | ||
90 | - } | ||
91 | - | ||
92 | - /** | ||
93 | - * Returns gateway IP address. | ||
94 | - * | ||
95 | - * @return gateway IP address | ||
96 | - */ | ||
97 | - public Ip4Address gatewayIP() { | ||
98 | - return gatewayIP; | ||
99 | - } | ||
100 | - | ||
101 | - /** | ||
102 | - * Returns network ID. | ||
103 | - * | ||
104 | - * @return network ID | ||
105 | - */ | ||
106 | - public String networkId() { | ||
107 | - return networkId; | ||
108 | - } | ||
109 | - | ||
110 | - /** | ||
111 | - * Returns the builder of the OpenstackPortInfo. | ||
112 | - * | ||
113 | - * @return OpenstackPortInfo builder reference | ||
114 | - */ | ||
115 | - public static OpenstackPortInfo.Builder builder() { | ||
116 | - return new Builder(); | ||
117 | - } | ||
118 | - | ||
119 | - /** | ||
120 | - * Represents the OpenstackPortInfo Builder. | ||
121 | - * | ||
122 | - */ | ||
123 | - public static final class Builder { | ||
124 | - private Ip4Address hostIp; | ||
125 | - private MacAddress hostMac; | ||
126 | - private DeviceId deviceId; | ||
127 | - private long vni; | ||
128 | - private Ip4Address gatewayIP; | ||
129 | - private String networkId; | ||
130 | - | ||
131 | - /** | ||
132 | - * Sets the IP address of the port. | ||
133 | - * | ||
134 | - * @param gatewayIP gateway IP | ||
135 | - * @return Builder reference | ||
136 | - */ | ||
137 | - public Builder setGatewayIP(Ip4Address gatewayIP) { | ||
138 | - this.gatewayIP = checkNotNull(gatewayIP, "gatewayIP cannot be null"); | ||
139 | - return this; | ||
140 | - } | ||
141 | - | ||
142 | - /** | ||
143 | - * Sets the network ID. | ||
144 | - * | ||
145 | - * @param networkId network id | ||
146 | - * @return Builder reference | ||
147 | - */ | ||
148 | - public Builder setNetworkId(String networkId) { | ||
149 | - this.networkId = checkNotNull(networkId, "networkId cannot be null"); | ||
150 | - return this; | ||
151 | - } | ||
152 | - | ||
153 | - /** | ||
154 | - * Sets the host IP address of the port. | ||
155 | - * | ||
156 | - * @param hostIp host IP address | ||
157 | - * @return Builder reference | ||
158 | - */ | ||
159 | - public Builder setHostIp(Ip4Address hostIp) { | ||
160 | - this.hostIp = checkNotNull(hostIp, "hostIp cannot be null"); | ||
161 | - return this; | ||
162 | - } | ||
163 | - | ||
164 | - /** | ||
165 | - * Sets the host MAC address of the port. | ||
166 | - * | ||
167 | - * @param hostMac host MAC address | ||
168 | - * @return Builder reference | ||
169 | - */ | ||
170 | - public Builder setHostMac(MacAddress hostMac) { | ||
171 | - this.hostMac = checkNotNull(hostMac, "hostMac cannot be bull"); | ||
172 | - return this; | ||
173 | - } | ||
174 | - | ||
175 | - /** | ||
176 | - * Sets the device ID. | ||
177 | - * | ||
178 | - * @param deviceId device ID | ||
179 | - * @return Builder reference | ||
180 | - */ | ||
181 | - public Builder setDeviceId(DeviceId deviceId) { | ||
182 | - this.deviceId = checkNotNull(deviceId, "deviceId cannot be null"); | ||
183 | - return this; | ||
184 | - } | ||
185 | - | ||
186 | - /** | ||
187 | - * Sets the tunnel ID. | ||
188 | - * | ||
189 | - * @param vni tunnel ID | ||
190 | - * @return Builder reference | ||
191 | - */ | ||
192 | - public Builder setVni(long vni) { | ||
193 | - this.vni = checkNotNull(vni, "vni cannot be null"); | ||
194 | - return this; | ||
195 | - } | ||
196 | - | ||
197 | - /** | ||
198 | - * Builds the OpenstackPortInfo reference. | ||
199 | - * | ||
200 | - * @return OpenstackPortInfo reference | ||
201 | - */ | ||
202 | - public OpenstackPortInfo build() { | ||
203 | - return new OpenstackPortInfo(hostIp, hostMac, deviceId, vni, gatewayIP, networkId); | ||
204 | - } | ||
205 | - } | ||
206 | -} |
... | @@ -85,8 +85,8 @@ public interface OpenstackRoutingService { | ... | @@ -85,8 +85,8 @@ public interface OpenstackRoutingService { |
85 | * | 85 | * |
86 | * @param portId Deleted vm | 86 | * @param portId Deleted vm |
87 | * @param portInfo stored information about deleted vm | 87 | * @param portInfo stored information about deleted vm |
88 | - */ | ||
89 | void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo); | 88 | void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo); |
89 | + */ | ||
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Returns network id for routerInterface. | 92 | * Returns network id for routerInterface. | ... | ... |
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.openstacknetworking; | ||
17 | - | ||
18 | -import java.util.Map; | ||
19 | - | ||
20 | -/** | ||
21 | - * Handles port management REST API from Openstack for VMs. | ||
22 | - */ | ||
23 | -// TODO remove this | ||
24 | -public interface OpenstackSwitchingService { | ||
25 | - | ||
26 | - /** | ||
27 | - * Retruns OpenstackPortInfo map. | ||
28 | - * | ||
29 | - * @return OpenstackPortInfo map | ||
30 | - */ | ||
31 | - // TODO remove this | ||
32 | - Map<String, OpenstackPortInfo> openstackPortInfo(); | ||
33 | -} |
... | @@ -68,6 +68,11 @@ | ... | @@ -68,6 +68,11 @@ |
68 | <artifactId>onos-scalablegateway</artifactId> | 68 | <artifactId>onos-scalablegateway</artifactId> |
69 | <version>${project.version}</version> | 69 | <version>${project.version}</version> |
70 | </dependency> | 70 | </dependency> |
71 | + <dependency> | ||
72 | + <groupId>org.onosproject</groupId> | ||
73 | + <artifactId>onos-app-openstacknode</artifactId> | ||
74 | + <version>${project.version}</version> | ||
75 | + </dependency> | ||
71 | </dependencies> | 76 | </dependencies> |
72 | </project> | 77 | </project> |
73 | 78 | ... | ... |
... | @@ -15,34 +15,39 @@ | ... | @@ -15,34 +15,39 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstacknetworking.routing; | 16 | package org.onosproject.openstacknetworking.routing; |
17 | 17 | ||
18 | +import org.onosproject.net.Host; | ||
18 | import org.onosproject.openstackinterface.OpenstackFloatingIP; | 19 | import org.onosproject.openstackinterface.OpenstackFloatingIP; |
19 | -import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes. | 22 | * Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes. |
23 | */ | 23 | */ |
24 | public class OpenstackFloatingIPHandler implements Runnable { | 24 | public class OpenstackFloatingIPHandler implements Runnable { |
25 | 25 | ||
26 | + public enum Action { | ||
27 | + ASSOCIATE, | ||
28 | + DISSASSOCIATE | ||
29 | + } | ||
30 | + | ||
26 | private final OpenstackFloatingIP floatingIP; | 31 | private final OpenstackFloatingIP floatingIP; |
27 | private final OpenstackRoutingRulePopulator rulePopulator; | 32 | private final OpenstackRoutingRulePopulator rulePopulator; |
28 | - private boolean associate; | 33 | + private final Host host; |
29 | - private final OpenstackPortInfo portInfo; | 34 | + private final Action action; |
35 | + | ||
30 | 36 | ||
31 | OpenstackFloatingIPHandler(OpenstackRoutingRulePopulator rulePopulator, | 37 | OpenstackFloatingIPHandler(OpenstackRoutingRulePopulator rulePopulator, |
32 | - OpenstackFloatingIP openstackFloatingIP, boolean associate, OpenstackPortInfo portInfo) { | 38 | + OpenstackFloatingIP openstackFloatingIP, Action action, Host host) { |
33 | this.floatingIP = openstackFloatingIP; | 39 | this.floatingIP = openstackFloatingIP; |
34 | this.rulePopulator = rulePopulator; | 40 | this.rulePopulator = rulePopulator; |
35 | - this.associate = associate; | 41 | + this.action = action; |
36 | - this.portInfo = portInfo; | 42 | + this.host = host; |
37 | } | 43 | } |
38 | 44 | ||
39 | @Override | 45 | @Override |
40 | public void run() { | 46 | public void run() { |
41 | - if (associate) { | 47 | + if (action == Action.ASSOCIATE) { |
42 | rulePopulator.populateFloatingIpRules(floatingIP); | 48 | rulePopulator.populateFloatingIpRules(floatingIP); |
43 | } else { | 49 | } else { |
44 | - rulePopulator.removeFloatingIpRules(floatingIP, portInfo); | 50 | + rulePopulator.removeFloatingIpRules(floatingIP, host); |
45 | } | 51 | } |
46 | - | ||
47 | } | 52 | } |
48 | } | 53 | } | ... | ... |
... | @@ -20,9 +20,11 @@ import org.onlab.packet.Ethernet; | ... | @@ -20,9 +20,11 @@ import org.onlab.packet.Ethernet; |
20 | import org.onlab.packet.ICMP; | 20 | import org.onlab.packet.ICMP; |
21 | import org.onlab.packet.IPv4; | 21 | import org.onlab.packet.IPv4; |
22 | import org.onlab.packet.Ip4Address; | 22 | import org.onlab.packet.Ip4Address; |
23 | +import org.onlab.packet.IpAddress; | ||
23 | import org.onlab.packet.MacAddress; | 24 | import org.onlab.packet.MacAddress; |
24 | import org.onosproject.core.ApplicationId; | 25 | import org.onosproject.core.ApplicationId; |
25 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
27 | +import org.onosproject.net.Host; | ||
26 | import org.onosproject.net.Port; | 28 | import org.onosproject.net.Port; |
27 | import org.onosproject.net.PortNumber; | 29 | import org.onosproject.net.PortNumber; |
28 | import org.onosproject.net.device.DeviceService; | 30 | import org.onosproject.net.device.DeviceService; |
... | @@ -30,16 +32,17 @@ import org.onosproject.net.flow.DefaultTrafficSelector; | ... | @@ -30,16 +32,17 @@ import org.onosproject.net.flow.DefaultTrafficSelector; |
30 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 32 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
31 | import org.onosproject.net.flow.TrafficSelector; | 33 | import org.onosproject.net.flow.TrafficSelector; |
32 | import org.onosproject.net.flow.TrafficTreatment; | 34 | import org.onosproject.net.flow.TrafficTreatment; |
35 | +import org.onosproject.net.host.HostService; | ||
33 | import org.onosproject.net.packet.DefaultOutboundPacket; | 36 | import org.onosproject.net.packet.DefaultOutboundPacket; |
34 | import org.onosproject.net.packet.OutboundPacket; | 37 | import org.onosproject.net.packet.OutboundPacket; |
35 | import org.onosproject.net.packet.PacketContext; | 38 | import org.onosproject.net.packet.PacketContext; |
36 | import org.onosproject.net.packet.PacketPriority; | 39 | import org.onosproject.net.packet.PacketPriority; |
37 | import org.onosproject.net.packet.PacketService; | 40 | import org.onosproject.net.packet.PacketService; |
41 | +import org.onosproject.openstacknetworking.Constants; | ||
38 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 42 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
39 | import org.onosproject.openstackinterface.OpenstackPort; | 43 | import org.onosproject.openstackinterface.OpenstackPort; |
40 | -import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | 44 | +import org.onosproject.openstacknode.OpenstackNode; |
41 | -import org.onosproject.openstacknetworking.OpenstackPortInfo; | 45 | +import org.onosproject.openstacknode.OpenstackNodeService; |
42 | -import org.onosproject.openstacknetworking.OpenstackSwitchingService; | ||
43 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 46 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
44 | import org.slf4j.Logger; | 47 | import org.slf4j.Logger; |
45 | 48 | ||
... | @@ -58,37 +61,39 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -58,37 +61,39 @@ import static org.slf4j.LoggerFactory.getLogger; |
58 | public class OpenstackIcmpHandler { | 61 | public class OpenstackIcmpHandler { |
59 | protected final Logger log = getLogger(getClass()); | 62 | protected final Logger log = getLogger(getClass()); |
60 | 63 | ||
61 | - private final PacketService packetService; | 64 | + |
62 | - private final DeviceService deviceService; | ||
63 | - private final Map<String, OpenstackPortInfo> icmpInfoMap = Maps.newHashMap(); | ||
64 | - private final OpenstackSwitchingService openstackSwitchingService; | ||
65 | - private final OpenstackInterfaceService openstackService; | ||
66 | - private final ScalableGatewayService gatewayService; | ||
67 | - private final OpenstackNetworkingConfig config; | ||
68 | - private static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); | ||
69 | private static final String NETWORK_ROUTER_INTERFACE = "network:router_interface"; | 65 | private static final String NETWORK_ROUTER_INTERFACE = "network:router_interface"; |
70 | private static final String PORTNAME = "portName"; | 66 | private static final String PORTNAME = "portName"; |
71 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; | 67 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; |
72 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; | 68 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; |
73 | - private static final String EXTERNAL_NODE_NULL = "There is no external node about this deviceId []"; | 69 | + |
70 | + private final PacketService packetService; | ||
71 | + private final DeviceService deviceService; | ||
72 | + private final ScalableGatewayService gatewayService; | ||
73 | + private final HostService hostService; | ||
74 | + private final Map<String, Host> icmpInfoMap = Maps.newHashMap(); | ||
75 | + private final OpenstackInterfaceService openstackService; | ||
76 | + private final OpenstackNodeService nodeService; | ||
77 | + | ||
74 | /** | 78 | /** |
75 | * Default constructor. | 79 | * Default constructor. |
76 | * | 80 | * |
77 | * @param packetService packet service | 81 | * @param packetService packet service |
78 | * @param deviceService device service | 82 | * @param deviceService device service |
79 | * @param openstackService openstackInterface service | 83 | * @param openstackService openstackInterface service |
80 | - * @param config openstackRoutingConfig | ||
81 | - * @param openstackSwitchingService openstackSwitching service | ||
82 | - * @param gatewayService scalable gateway service | ||
83 | */ | 84 | */ |
84 | - OpenstackIcmpHandler(PacketService packetService, DeviceService deviceService, | 85 | + OpenstackIcmpHandler(PacketService packetService, |
85 | - OpenstackInterfaceService openstackService, OpenstackNetworkingConfig config, | 86 | + DeviceService deviceService, |
86 | - OpenstackSwitchingService openstackSwitchingService, ScalableGatewayService gatewayService) { | 87 | + HostService hostService, |
88 | + OpenstackInterfaceService openstackService, | ||
89 | + OpenstackNodeService nodeService, | ||
90 | + ScalableGatewayService gatewayService | ||
91 | + ) { | ||
87 | this.packetService = packetService; | 92 | this.packetService = packetService; |
88 | this.deviceService = deviceService; | 93 | this.deviceService = deviceService; |
94 | + this.hostService = hostService; | ||
89 | this.openstackService = checkNotNull(openstackService); | 95 | this.openstackService = checkNotNull(openstackService); |
90 | - this.config = checkNotNull(config); | 96 | + this.nodeService = nodeService; |
91 | - this.openstackSwitchingService = checkNotNull(openstackSwitchingService); | ||
92 | this.gatewayService = gatewayService; | 97 | this.gatewayService = gatewayService; |
93 | } | 98 | } |
94 | 99 | ||
... | @@ -103,13 +108,20 @@ public class OpenstackIcmpHandler { | ... | @@ -103,13 +108,20 @@ public class OpenstackIcmpHandler { |
103 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) | 108 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) |
104 | .build(); | 109 | .build(); |
105 | 110 | ||
106 | - Map<DeviceId, PortNumber> externalInfoMap = getExternalInfo(); | 111 | + // TODO: Return the correct gateway node |
112 | + Optional<OpenstackNode> gwNode = nodeService.nodes().stream() | ||
113 | + .filter(n -> n.type().equals(OpenstackNodeService.NodeType.GATEWAY)) | ||
114 | + .findFirst(); | ||
115 | + | ||
116 | + if (!gwNode.isPresent()) { | ||
117 | + log.warn("No Gateway is defined."); | ||
118 | + return; | ||
119 | + } | ||
107 | 120 | ||
108 | - externalInfoMap.keySet().forEach(deviceId -> | 121 | + packetService.requestPackets(icmpSelector, |
109 | - packetService.requestPackets(icmpSelector, | 122 | + PacketPriority.CONTROL, |
110 | - PacketPriority.CONTROL, | 123 | + appId, |
111 | - appId, | 124 | + Optional.of(gwNode.get().intBridge())); |
112 | - Optional.of(deviceId))); | ||
113 | } | 125 | } |
114 | 126 | ||
115 | /** | 127 | /** |
... | @@ -135,11 +147,13 @@ public class OpenstackIcmpHandler { | ... | @@ -135,11 +147,13 @@ public class OpenstackIcmpHandler { |
135 | if (icmp.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) { | 147 | if (icmp.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) { |
136 | //TODO: Considers icmp between internal subnets which are belonged to the same router. | 148 | //TODO: Considers icmp between internal subnets which are belonged to the same router. |
137 | 149 | ||
138 | - OpenstackPortInfo openstackPortInfo = | 150 | + //OpenstackPortInfo openstackPortInfo = |
139 | - getOpenstackPortInfo(Ip4Address.valueOf(ipPacket.getSourceAddress()), ethernet.getSourceMAC()); | 151 | + // getOpenstackPortInfo(Ip4Address.valueOf(ipPacket.getSourceAddress()), ethernet.getSourceMAC()); |
140 | 152 | ||
141 | //checkNotNull(openstackPortInfo, "openstackPortInfo can not be null"); | 153 | //checkNotNull(openstackPortInfo, "openstackPortInfo can not be null"); |
154 | + /* XXX Is this handling ICMP to gateway ????? | ||
142 | if (requestToOpenstackRoutingNetwork(ipPacket.getDestinationAddress())) { | 155 | if (requestToOpenstackRoutingNetwork(ipPacket.getDestinationAddress())) { |
156 | + Host host = | ||
143 | if (openstackPortInfo == null) { | 157 | if (openstackPortInfo == null) { |
144 | if (config.gatewayBridgeId().equals(context.inPacket().receivedFrom().deviceId().toString())) { | 158 | if (config.gatewayBridgeId().equals(context.inPacket().receivedFrom().deviceId().toString())) { |
145 | if (portNumber.equals(getPortForAnnotationPortName(deviceId, | 159 | if (portNumber.equals(getPortForAnnotationPortName(deviceId, |
... | @@ -151,15 +165,23 @@ public class OpenstackIcmpHandler { | ... | @@ -151,15 +165,23 @@ public class OpenstackIcmpHandler { |
151 | } | 165 | } |
152 | return; | 166 | return; |
153 | } else { | 167 | } else { |
154 | - processIcmpPacketSentToGateway(ipPacket, icmp, openstackPortInfo); | 168 | + processIcmpPacketSentToGateway(ipPacket, icmp, host); |
155 | return; | 169 | return; |
156 | } | 170 | } |
157 | } | 171 | } |
172 | + */ | ||
158 | 173 | ||
159 | - if (ipPacket.getDestinationAddress() == openstackPortInfo.gatewayIP().toInt()) { | 174 | + Optional<Host> host = hostService.getHostsByMac(ethernet.getSourceMAC()).stream().findFirst(); |
160 | - processIcmpPacketSentToGateway(ipPacket, icmp, openstackPortInfo); | 175 | + if (!host.isPresent()) { |
176 | + log.warn("No host found for MAC {}", ethernet.getSourceMAC()); | ||
177 | + return; | ||
178 | + } | ||
179 | + | ||
180 | + IpAddress gatewayIp = IpAddress.valueOf(host.get().annotations().value(Constants.GATEWAY_IP)); | ||
181 | + if (ipPacket.getDestinationAddress() == gatewayIp.getIp4Address().toInt()) { | ||
182 | + processIcmpPacketSentToGateway(ipPacket, icmp, host.get()); | ||
161 | } else { | 183 | } else { |
162 | - Ip4Address pNatIpAddress = pNatIpForPort(openstackPortInfo); | 184 | + Ip4Address pNatIpAddress = pNatIpForPort(host.get()); |
163 | checkNotNull(pNatIpAddress, "pNatIpAddress can not be null"); | 185 | checkNotNull(pNatIpAddress, "pNatIpAddress can not be null"); |
164 | 186 | ||
165 | sendRequestPacketToExt(ipPacket, icmp, deviceId, pNatIpAddress); | 187 | sendRequestPacketToExt(ipPacket, icmp, deviceId, pNatIpAddress); |
... | @@ -167,7 +189,7 @@ public class OpenstackIcmpHandler { | ... | @@ -167,7 +189,7 @@ public class OpenstackIcmpHandler { |
167 | String icmpInfoKey = String.valueOf(icmpId) | 189 | String icmpInfoKey = String.valueOf(icmpId) |
168 | .concat(String.valueOf(pNatIpAddress.toInt())) | 190 | .concat(String.valueOf(pNatIpAddress.toInt())) |
169 | .concat(String.valueOf(ipPacket.getDestinationAddress())); | 191 | .concat(String.valueOf(ipPacket.getDestinationAddress())); |
170 | - icmpInfoMap.putIfAbsent(icmpInfoKey, openstackPortInfo); | 192 | + icmpInfoMap.putIfAbsent(icmpInfoKey, host.get()); |
171 | } | 193 | } |
172 | } else if (icmp.getIcmpType() == ICMP.TYPE_ECHO_REPLY) { | 194 | } else if (icmp.getIcmpType() == ICMP.TYPE_ECHO_REPLY) { |
173 | String icmpInfoKey = String.valueOf(icmpId) | 195 | String icmpInfoKey = String.valueOf(icmpId) |
... | @@ -190,7 +212,8 @@ public class OpenstackIcmpHandler { | ... | @@ -190,7 +212,8 @@ public class OpenstackIcmpHandler { |
190 | icmpRequestIpv4.setPayload(icmpRequest); | 212 | icmpRequestIpv4.setPayload(icmpRequest); |
191 | Ethernet icmpResponseEth = new Ethernet(); | 213 | Ethernet icmpResponseEth = new Ethernet(); |
192 | icmpResponseEth.setEtherType(Ethernet.TYPE_IPV4) | 214 | icmpResponseEth.setEtherType(Ethernet.TYPE_IPV4) |
193 | - .setSourceMACAddress(config.gatewayExternalInterfaceMac()) | 215 | + // TODO: Get the correct GW MAC |
216 | + .setSourceMACAddress(Constants.GW_EXT_INT_MAC) | ||
194 | .setDestinationMACAddress(destMac).setPayload(icmpRequestIpv4); | 217 | .setDestinationMACAddress(destMac).setPayload(icmpRequestIpv4); |
195 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(portNumber).build(); | 218 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(portNumber).build(); |
196 | OutboundPacket packet = new DefaultOutboundPacket(deviceId, | 219 | OutboundPacket packet = new DefaultOutboundPacket(deviceId, |
... | @@ -199,13 +222,14 @@ public class OpenstackIcmpHandler { | ... | @@ -199,13 +222,14 @@ public class OpenstackIcmpHandler { |
199 | } | 222 | } |
200 | 223 | ||
201 | private void processIcmpPacketSentToGateway(IPv4 icmpRequestIpv4, ICMP icmpRequest, | 224 | private void processIcmpPacketSentToGateway(IPv4 icmpRequestIpv4, ICMP icmpRequest, |
202 | - OpenstackPortInfo openstackPortInfo) { | 225 | + Host host) { |
203 | icmpRequest.setChecksum((short) 0); | 226 | icmpRequest.setChecksum((short) 0); |
204 | icmpRequest.setIcmpType(ICMP.TYPE_ECHO_REPLY) | 227 | icmpRequest.setIcmpType(ICMP.TYPE_ECHO_REPLY) |
205 | .resetChecksum(); | 228 | .resetChecksum(); |
206 | 229 | ||
230 | + Ip4Address ipAddress = host.ipAddresses().stream().findAny().get().getIp4Address(); | ||
207 | icmpRequestIpv4.setSourceAddress(icmpRequestIpv4.getDestinationAddress()) | 231 | icmpRequestIpv4.setSourceAddress(icmpRequestIpv4.getDestinationAddress()) |
208 | - .setDestinationAddress(openstackPortInfo.ip().toInt()) | 232 | + .setDestinationAddress(ipAddress.toInt()) |
209 | .resetChecksum(); | 233 | .resetChecksum(); |
210 | 234 | ||
211 | icmpRequestIpv4.setPayload(icmpRequest); | 235 | icmpRequestIpv4.setPayload(icmpRequest); |
... | @@ -213,11 +237,11 @@ public class OpenstackIcmpHandler { | ... | @@ -213,11 +237,11 @@ public class OpenstackIcmpHandler { |
213 | Ethernet icmpResponseEth = new Ethernet(); | 237 | Ethernet icmpResponseEth = new Ethernet(); |
214 | 238 | ||
215 | icmpResponseEth.setEtherType(Ethernet.TYPE_IPV4) | 239 | icmpResponseEth.setEtherType(Ethernet.TYPE_IPV4) |
216 | - .setSourceMACAddress(GATEWAY_MAC) | 240 | + .setSourceMACAddress(Constants.GATEWAY_MAC) |
217 | - .setDestinationMACAddress(openstackPortInfo.mac()) | 241 | + .setDestinationMACAddress(host.mac()) |
218 | .setPayload(icmpRequestIpv4); | 242 | .setPayload(icmpRequestIpv4); |
219 | 243 | ||
220 | - sendResponsePacketToHost(icmpResponseEth, openstackPortInfo); | 244 | + sendResponsePacketToHost(icmpResponseEth, host); |
221 | } | 245 | } |
222 | 246 | ||
223 | private void sendRequestPacketToExt(IPv4 icmpRequestIpv4, ICMP icmpRequest, DeviceId deviceId, | 247 | private void sendRequestPacketToExt(IPv4 icmpRequestIpv4, ICMP icmpRequest, DeviceId deviceId, |
... | @@ -230,19 +254,27 @@ public class OpenstackIcmpHandler { | ... | @@ -230,19 +254,27 @@ public class OpenstackIcmpHandler { |
230 | Ethernet icmpRequestEth = new Ethernet(); | 254 | Ethernet icmpRequestEth = new Ethernet(); |
231 | 255 | ||
232 | icmpRequestEth.setEtherType(Ethernet.TYPE_IPV4) | 256 | icmpRequestEth.setEtherType(Ethernet.TYPE_IPV4) |
257 | + // TODO: Get the correct one - Scalable Gateway ... | ||
258 | + .setSourceMACAddress(Constants.GW_EXT_INT_MAC) | ||
259 | + .setDestinationMACAddress(Constants.PHY_ROUTER_MAC) | ||
233 | .setPayload(icmpRequestIpv4); | 260 | .setPayload(icmpRequestIpv4); |
234 | 261 | ||
235 | - TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | 262 | + // TODO: Return the correct gateway node |
263 | + Optional<OpenstackNode> gwNode = nodeService.nodes().stream() | ||
264 | + .filter(n -> n.type().equals(OpenstackNodeService.NodeType.GATEWAY)) | ||
265 | + .findFirst(); | ||
236 | 266 | ||
237 | - Map<DeviceId, PortNumber> externalInforMap = getExternalInfo(); | 267 | + if (!gwNode.isPresent()) { |
238 | - | 268 | + log.warn("No Gateway is defined."); |
239 | - if (externalInforMap.size() == 0 || !externalInforMap.containsKey(deviceId)) { | ||
240 | - log.error(EXTERNAL_NODE_NULL, deviceId.toString()); | ||
241 | return; | 269 | return; |
242 | } | 270 | } |
243 | - tBuilder.setOutput(externalInforMap.get(deviceId)); | ||
244 | 271 | ||
245 | - TrafficTreatment treatment = tBuilder.build(); | 272 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
273 | + // FIXME: please double check this. | ||
274 | + .setOutput(getPortForAnnotationPortName(gwNode.get().intBridge(), | ||
275 | + // FIXME: please double check this. | ||
276 | + org.onosproject.openstacknode.Constants.PATCH_INTG_BRIDGE)) | ||
277 | + .build(); | ||
246 | 278 | ||
247 | OutboundPacket packet = new DefaultOutboundPacket(deviceId, | 279 | OutboundPacket packet = new DefaultOutboundPacket(deviceId, |
248 | treatment, ByteBuffer.wrap(icmpRequestEth.serialize())); | 280 | treatment, ByteBuffer.wrap(icmpRequestEth.serialize())); |
... | @@ -251,59 +283,45 @@ public class OpenstackIcmpHandler { | ... | @@ -251,59 +283,45 @@ public class OpenstackIcmpHandler { |
251 | } | 283 | } |
252 | 284 | ||
253 | private void processResponsePacketFromExternalToHost(IPv4 icmpResponseIpv4, ICMP icmpResponse, | 285 | private void processResponsePacketFromExternalToHost(IPv4 icmpResponseIpv4, ICMP icmpResponse, |
254 | - OpenstackPortInfo openstackPortInfo) { | 286 | + Host host) { |
255 | icmpResponse.resetChecksum(); | 287 | icmpResponse.resetChecksum(); |
256 | 288 | ||
257 | - icmpResponseIpv4.setDestinationAddress(openstackPortInfo.ip().toInt()) | 289 | + Ip4Address ipAddress = host.ipAddresses().stream().findFirst().get().getIp4Address(); |
290 | + icmpResponseIpv4.setDestinationAddress(ipAddress.toInt()) | ||
258 | .resetChecksum(); | 291 | .resetChecksum(); |
259 | icmpResponseIpv4.setPayload(icmpResponse); | 292 | icmpResponseIpv4.setPayload(icmpResponse); |
260 | 293 | ||
261 | Ethernet icmpResponseEth = new Ethernet(); | 294 | Ethernet icmpResponseEth = new Ethernet(); |
262 | 295 | ||
263 | icmpResponseEth.setEtherType(Ethernet.TYPE_IPV4) | 296 | icmpResponseEth.setEtherType(Ethernet.TYPE_IPV4) |
264 | - .setSourceMACAddress(GATEWAY_MAC) | 297 | + .setSourceMACAddress(Constants.GATEWAY_MAC) |
265 | - .setDestinationMACAddress(openstackPortInfo.mac()) | 298 | + .setDestinationMACAddress(host.mac()) |
266 | .setPayload(icmpResponseIpv4); | 299 | .setPayload(icmpResponseIpv4); |
267 | 300 | ||
268 | - sendResponsePacketToHost(icmpResponseEth, openstackPortInfo); | 301 | + sendResponsePacketToHost(icmpResponseEth, host); |
269 | } | 302 | } |
270 | 303 | ||
271 | - private void sendResponsePacketToHost(Ethernet icmpResponseEth, OpenstackPortInfo openstackPortInfo) { | 304 | + private void sendResponsePacketToHost(Ethernet icmpResponseEth, Host host) { |
272 | - Map.Entry<String, OpenstackPortInfo> entry = openstackSwitchingService.openstackPortInfo().entrySet().stream() | ||
273 | - .filter(e -> e.getValue().mac().equals(openstackPortInfo.mac())) | ||
274 | - .findAny().orElse(null); | ||
275 | - | ||
276 | - if (entry == null) { | ||
277 | - return; | ||
278 | - } | ||
279 | 305 | ||
280 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 306 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
281 | - .setOutput(getPortForAnnotationPortName(openstackPortInfo.deviceId(), entry.getKey())) | 307 | + .setOutput(host.location().port()) |
282 | .build(); | 308 | .build(); |
283 | 309 | ||
284 | - OutboundPacket packet = new DefaultOutboundPacket(openstackPortInfo.deviceId(), | 310 | + OutboundPacket packet = new DefaultOutboundPacket(host.location().deviceId(), |
285 | treatment, ByteBuffer.wrap(icmpResponseEth.serialize())); | 311 | treatment, ByteBuffer.wrap(icmpResponseEth.serialize())); |
286 | 312 | ||
287 | packetService.emit(packet); | 313 | packetService.emit(packet); |
288 | } | 314 | } |
289 | 315 | ||
290 | - private OpenstackPortInfo getOpenstackPortInfo(Ip4Address sourceIp, MacAddress sourceMac) { | ||
291 | - checkNotNull(openstackSwitchingService.openstackPortInfo(), "openstackportinfo collection can not be null"); | ||
292 | - | ||
293 | - return openstackSwitchingService.openstackPortInfo().values() | ||
294 | - .stream().filter(p -> p.ip().equals(sourceIp) && p.mac().equals(sourceMac)) | ||
295 | - .findAny().orElse(null); | ||
296 | - } | ||
297 | - | ||
298 | private short getIcmpId(ICMP icmp) { | 316 | private short getIcmpId(ICMP icmp) { |
299 | return ByteBuffer.wrap(icmp.serialize(), 4, 2).getShort(); | 317 | return ByteBuffer.wrap(icmp.serialize(), 4, 2).getShort(); |
300 | } | 318 | } |
301 | 319 | ||
302 | - private Ip4Address pNatIpForPort(OpenstackPortInfo openstackPortInfo) { | 320 | + private Ip4Address pNatIpForPort(Host host) { |
303 | 321 | ||
304 | OpenstackPort openstackPort = openstackService.ports().stream() | 322 | OpenstackPort openstackPort = openstackService.ports().stream() |
305 | .filter(p -> p.deviceOwner().equals(NETWORK_ROUTER_INTERFACE) && | 323 | .filter(p -> p.deviceOwner().equals(NETWORK_ROUTER_INTERFACE) && |
306 | - p.networkId().equals(openstackPortInfo.networkId())) | 324 | + p.networkId().equals(host.annotations().value(Constants.NETWORK_ID))) |
307 | .findAny().orElse(null); | 325 | .findAny().orElse(null); |
308 | 326 | ||
309 | checkNotNull(openstackPort, "openstackPort can not be null"); | 327 | checkNotNull(openstackPort, "openstackPort can not be null"); | ... | ... |
... | @@ -32,7 +32,6 @@ import org.onosproject.net.packet.PacketService; | ... | @@ -32,7 +32,6 @@ import org.onosproject.net.packet.PacketService; |
32 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 32 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
33 | import org.onosproject.openstackinterface.OpenstackPort; | 33 | import org.onosproject.openstackinterface.OpenstackPort; |
34 | import org.onosproject.openstackinterface.OpenstackRouter; | 34 | import org.onosproject.openstackinterface.OpenstackRouter; |
35 | -import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | ||
36 | import org.onosproject.scalablegateway.api.GatewayNode; | 35 | import org.onosproject.scalablegateway.api.GatewayNode; |
37 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 36 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
38 | import org.slf4j.Logger; | 37 | import org.slf4j.Logger; |
... | @@ -52,25 +51,21 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -52,25 +51,21 @@ public class OpenstackPnatHandler implements Runnable { |
52 | volatile PacketContext context; | 51 | volatile PacketContext context; |
53 | private final Logger log = LoggerFactory.getLogger(getClass()); | 52 | private final Logger log = LoggerFactory.getLogger(getClass()); |
54 | 53 | ||
55 | - protected PacketService packetService; | ||
56 | - | ||
57 | private final OpenstackRoutingRulePopulator rulePopulator; | 54 | private final OpenstackRoutingRulePopulator rulePopulator; |
58 | private final int portNum; | 55 | private final int portNum; |
59 | private final OpenstackPort openstackPort; | 56 | private final OpenstackPort openstackPort; |
60 | private final Port port; | 57 | private final Port port; |
61 | - private OpenstackNetworkingConfig config; | ||
62 | 58 | ||
63 | private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; | 59 | 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 []"; | 60 | private static final String EXTERNAL_PORT_NULL = "There is no external port in this deviceId []"; |
65 | 61 | ||
66 | OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context, | 62 | OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context, |
67 | - int portNum, OpenstackPort openstackPort, Port port, OpenstackNetworkingConfig config) { | 63 | + int portNum, OpenstackPort openstackPort, Port port) { |
68 | this.rulePopulator = checkNotNull(rulePopulator); | 64 | this.rulePopulator = checkNotNull(rulePopulator); |
69 | this.context = checkNotNull(context); | 65 | this.context = checkNotNull(context); |
70 | this.portNum = checkNotNull(portNum); | 66 | this.portNum = checkNotNull(portNum); |
71 | this.openstackPort = checkNotNull(openstackPort); | 67 | this.openstackPort = checkNotNull(openstackPort); |
72 | this.port = checkNotNull(port); | 68 | this.port = checkNotNull(port); |
73 | - this.config = checkNotNull(config); | ||
74 | } | 69 | } |
75 | 70 | ||
76 | @Override | 71 | @Override |
... | @@ -149,6 +144,7 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -149,6 +144,7 @@ public class OpenstackPnatHandler implements Runnable { |
149 | iPacket.resetChecksum(); | 144 | iPacket.resetChecksum(); |
150 | iPacket.setParent(ethernet); | 145 | iPacket.setParent(ethernet); |
151 | ethernet.setPayload(iPacket); | 146 | ethernet.setPayload(iPacket); |
147 | + | ||
152 | ScalableGatewayService gatewayService = getService(ScalableGatewayService.class); | 148 | ScalableGatewayService gatewayService = getService(ScalableGatewayService.class); |
153 | GatewayNode gatewayNode = gatewayService.getGatewayNode(deviceId); | 149 | GatewayNode gatewayNode = gatewayService.getGatewayNode(deviceId); |
154 | if (gatewayNode.getGatewayExternalInterfaceNames().size() == 0) { | 150 | if (gatewayNode.getGatewayExternalInterfaceNames().size() == 0) { |
... | @@ -159,7 +155,6 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -159,7 +155,6 @@ public class OpenstackPnatHandler implements Runnable { |
159 | 155 | ||
160 | ethernet.resetChecksum(); | 156 | ethernet.resetChecksum(); |
161 | 157 | ||
162 | - | ||
163 | packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(), | 158 | packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(), |
164 | ByteBuffer.wrap(ethernet.serialize()))); | 159 | ByteBuffer.wrap(ethernet.serialize()))); |
165 | } | 160 | } | ... | ... |
... | @@ -34,8 +34,9 @@ import org.onosproject.net.packet.PacketPriority; | ... | @@ -34,8 +34,9 @@ import org.onosproject.net.packet.PacketPriority; |
34 | import org.onosproject.net.packet.PacketService; | 34 | import org.onosproject.net.packet.PacketService; |
35 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 35 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
36 | import org.onosproject.openstackinterface.OpenstackPort; | 36 | import org.onosproject.openstackinterface.OpenstackPort; |
37 | -import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | ||
38 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 37 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
38 | +import org.onosproject.openstacknetworking.Constants; | ||
39 | +import org.onosproject.openstacknode.OpenstackNodeService; | ||
39 | import org.slf4j.Logger; | 40 | import org.slf4j.Logger; |
40 | 41 | ||
41 | import java.nio.ByteBuffer; | 42 | import java.nio.ByteBuffer; |
... | @@ -53,23 +54,24 @@ public class OpenstackRoutingArpHandler { | ... | @@ -53,23 +54,24 @@ public class OpenstackRoutingArpHandler { |
53 | 54 | ||
54 | private final PacketService packetService; | 55 | private final PacketService packetService; |
55 | private final OpenstackInterfaceService openstackService; | 56 | private final OpenstackInterfaceService openstackService; |
56 | - private final OpenstackNetworkingConfig config; | ||
57 | private final ScalableGatewayService gatewayService; | 57 | private final ScalableGatewayService gatewayService; |
58 | + private final OpenstackNodeService nodeService; | ||
58 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; | 59 | private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; |
59 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; | 60 | private static final String NETWORK_FLOATING_IP = "network:floatingip"; |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * Default constructor. | 63 | * Default constructor. |
63 | - * @param packetService packet service | 64 | + * |
65 | + * @param packetService packet service | ||
64 | * @param openstackService openstackInterface service | 66 | * @param openstackService openstackInterface service |
65 | - * @param config openstackRoutingConfig | 67 | + * @param gatewayService gateway service |
66 | - * @param gatewayService | 68 | + * @param nodeService openstackNodeService |
67 | */ | 69 | */ |
68 | OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService, | 70 | OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService, |
69 | - OpenstackNetworkingConfig config, ScalableGatewayService gatewayService) { | 71 | + OpenstackNodeService nodeService, ScalableGatewayService gatewayService) { |
70 | this.packetService = packetService; | 72 | this.packetService = packetService; |
71 | this.openstackService = checkNotNull(openstackService); | 73 | this.openstackService = checkNotNull(openstackService); |
72 | - this.config = checkNotNull(config); | 74 | + this.nodeService = nodeService; |
73 | this.gatewayService = gatewayService; | 75 | this.gatewayService = gatewayService; |
74 | } | 76 | } |
75 | 77 | ||
... | @@ -118,7 +120,8 @@ public class OpenstackRoutingArpHandler { | ... | @@ -118,7 +120,8 @@ public class OpenstackRoutingArpHandler { |
118 | if (getTargetMacForTargetIp(targetIp.getIp4Address()) == MacAddress.NONE) { | 120 | if (getTargetMacForTargetIp(targetIp.getIp4Address()) == MacAddress.NONE) { |
119 | return; | 121 | return; |
120 | } | 122 | } |
121 | - MacAddress targetMac = MacAddress.valueOf(config.gatewayExternalInterfaceMac()); | 123 | + // FIXME: Set the correct gateway |
124 | + MacAddress targetMac = Constants.GW_EXT_INT_MAC; | ||
122 | 125 | ||
123 | Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), | 126 | Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), |
124 | targetMac, ethernet); | 127 | targetMac, ethernet); | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.openstacknetworking.routing; | 16 | package org.onosproject.openstacknetworking.routing; |
17 | 17 | ||
18 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
19 | +import com.google.common.collect.Sets; | ||
19 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
20 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
21 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -25,38 +26,47 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -25,38 +26,47 @@ import org.apache.felix.scr.annotations.Service; |
25 | import org.onlab.packet.Ethernet; | 26 | import org.onlab.packet.Ethernet; |
26 | import org.onlab.packet.IPv4; | 27 | import org.onlab.packet.IPv4; |
27 | import org.onlab.packet.Ip4Address; | 28 | import org.onlab.packet.Ip4Address; |
29 | +import org.onlab.packet.IpAddress; | ||
28 | import org.onlab.packet.MacAddress; | 30 | import org.onlab.packet.MacAddress; |
29 | import org.onlab.packet.UDP; | 31 | import org.onlab.packet.UDP; |
30 | import org.onlab.util.KryoNamespace; | 32 | import org.onlab.util.KryoNamespace; |
31 | import org.onosproject.core.ApplicationId; | 33 | import org.onosproject.core.ApplicationId; |
32 | import org.onosproject.core.CoreService; | 34 | import org.onosproject.core.CoreService; |
35 | +import org.onosproject.mastership.MastershipService; | ||
36 | +import org.onosproject.net.DefaultAnnotations; | ||
33 | import org.onosproject.net.DeviceId; | 37 | import org.onosproject.net.DeviceId; |
38 | +import org.onosproject.net.Host; | ||
34 | import org.onosproject.net.Port; | 39 | import org.onosproject.net.Port; |
35 | -import org.onosproject.net.config.ConfigFactory; | ||
36 | -import org.onosproject.net.config.NetworkConfigEvent; | ||
37 | -import org.onosproject.net.config.NetworkConfigListener; | ||
38 | -import org.onosproject.net.config.NetworkConfigRegistry; | ||
39 | -import org.onosproject.net.config.NetworkConfigService; | ||
40 | -import org.onosproject.net.device.DeviceEvent; | ||
41 | -import org.onosproject.net.device.DeviceListener; | ||
42 | import org.onosproject.net.device.DeviceService; | 40 | import org.onosproject.net.device.DeviceService; |
43 | import org.onosproject.net.driver.DriverService; | 41 | import org.onosproject.net.driver.DriverService; |
44 | import org.onosproject.net.flowobjective.FlowObjectiveService; | 42 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
43 | +import org.onosproject.net.host.DefaultHostDescription; | ||
44 | +import org.onosproject.net.host.HostDescription; | ||
45 | +import org.onosproject.net.host.HostEvent; | ||
46 | +import org.onosproject.net.host.HostListener; | ||
47 | +import org.onosproject.net.host.HostProvider; | ||
48 | +import org.onosproject.net.host.HostProviderRegistry; | ||
49 | +import org.onosproject.net.host.HostProviderService; | ||
50 | +import org.onosproject.net.host.HostService; | ||
45 | import org.onosproject.net.packet.InboundPacket; | 51 | import org.onosproject.net.packet.InboundPacket; |
46 | import org.onosproject.net.packet.PacketContext; | 52 | import org.onosproject.net.packet.PacketContext; |
47 | import org.onosproject.net.packet.PacketProcessor; | 53 | import org.onosproject.net.packet.PacketProcessor; |
48 | import org.onosproject.net.packet.PacketService; | 54 | import org.onosproject.net.packet.PacketService; |
55 | +import org.onosproject.net.provider.AbstractProvider; | ||
56 | +import org.onosproject.net.provider.ProviderId; | ||
49 | import org.onosproject.openstackinterface.OpenstackFloatingIP; | 57 | import org.onosproject.openstackinterface.OpenstackFloatingIP; |
50 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 58 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
51 | import org.onosproject.openstackinterface.OpenstackPort; | 59 | import org.onosproject.openstackinterface.OpenstackPort; |
52 | import org.onosproject.openstackinterface.OpenstackRouter; | 60 | import org.onosproject.openstackinterface.OpenstackRouter; |
53 | import org.onosproject.openstackinterface.OpenstackRouterInterface; | 61 | import org.onosproject.openstackinterface.OpenstackRouterInterface; |
54 | -import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | ||
55 | -import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
56 | import org.onosproject.openstacknetworking.OpenstackRoutingService; | 62 | import org.onosproject.openstacknetworking.OpenstackRoutingService; |
57 | -import org.onosproject.openstacknetworking.OpenstackSubjectFactories; | ||
58 | -import org.onosproject.openstacknetworking.OpenstackSwitchingService; | ||
59 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 63 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
64 | +import org.onosproject.openstacknetworking.routing.OpenstackFloatingIPHandler.Action; | ||
65 | +import org.onosproject.openstacknetworking.Constants; | ||
66 | +import org.onosproject.openstacknode.OpenstackNode; | ||
67 | +import org.onosproject.openstacknode.OpenstackNodeEvent; | ||
68 | +import org.onosproject.openstacknode.OpenstackNodeListener; | ||
69 | +import org.onosproject.openstacknode.OpenstackNodeService; | ||
60 | import org.onosproject.store.serializers.KryoNamespaces; | 70 | import org.onosproject.store.serializers.KryoNamespaces; |
61 | import org.onosproject.store.service.ConsistentMap; | 71 | import org.onosproject.store.service.ConsistentMap; |
62 | import org.onosproject.store.service.Serializer; | 72 | import org.onosproject.store.service.Serializer; |
... | @@ -66,8 +76,8 @@ import org.slf4j.LoggerFactory; | ... | @@ -66,8 +76,8 @@ import org.slf4j.LoggerFactory; |
66 | 76 | ||
67 | import java.util.Collection; | 77 | import java.util.Collection; |
68 | import java.util.List; | 78 | import java.util.List; |
69 | -import java.util.Map; | ||
70 | import java.util.Optional; | 79 | import java.util.Optional; |
80 | +import java.util.Set; | ||
71 | import java.util.concurrent.ExecutorService; | 81 | import java.util.concurrent.ExecutorService; |
72 | import java.util.concurrent.Executors; | 82 | import java.util.concurrent.Executors; |
73 | import java.util.stream.Collectors; | 83 | import java.util.stream.Collectors; |
... | @@ -97,31 +107,35 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -97,31 +107,35 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
97 | protected OpenstackInterfaceService openstackService; | 107 | protected OpenstackInterfaceService openstackService; |
98 | 108 | ||
99 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
100 | - protected OpenstackSwitchingService openstackSwitchingService; | ||
101 | - | ||
102 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
103 | protected FlowObjectiveService flowObjectiveService; | 110 | protected FlowObjectiveService flowObjectiveService; |
104 | 111 | ||
105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
106 | protected DriverService driverService; | 113 | protected DriverService driverService; |
107 | 114 | ||
108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
109 | - protected NetworkConfigService configService; | 116 | + protected StorageService storageService; |
110 | 117 | ||
111 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 118 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
112 | - protected NetworkConfigRegistry configRegistry; | 119 | + protected HostService hostService; |
113 | 120 | ||
114 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 121 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
115 | - protected StorageService storageService; | 122 | + protected HostProviderRegistry hostProviderRegistry; |
116 | 123 | ||
117 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 124 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
118 | protected ScalableGatewayService gatewayService; | 125 | protected ScalableGatewayService gatewayService; |
119 | 126 | ||
127 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
128 | + protected OpenstackNodeService nodeService; | ||
129 | + | ||
130 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
131 | + protected MastershipService mastershipService; | ||
132 | + | ||
120 | private ApplicationId appId; | 133 | private ApplicationId appId; |
121 | private ConsistentMap<Integer, String> tpPortNumMap; // Map<PortNum, allocated VM`s Mac & destionation Ip address> | 134 | private ConsistentMap<Integer, String> tpPortNumMap; // Map<PortNum, allocated VM`s Mac & destionation Ip address> |
122 | private ConsistentMap<String, OpenstackFloatingIP> floatingIpMap; // Map<FloatingIp`s Id, FloatingIp object> | 135 | private ConsistentMap<String, OpenstackFloatingIP> floatingIpMap; // Map<FloatingIp`s Id, FloatingIp object> |
123 | // Map<RouterInterface`s portId, Corresponded port`s network id> | 136 | // Map<RouterInterface`s portId, Corresponded port`s network id> |
124 | private ConsistentMap<String, String> routerInterfaceMap; | 137 | private ConsistentMap<String, String> routerInterfaceMap; |
138 | + private static final ProviderId PID = new ProviderId("of", "org.onosproject.openstackroutering", true); | ||
125 | private static final String APP_ID = "org.onosproject.openstackrouting"; | 139 | private static final String APP_ID = "org.onosproject.openstackrouting"; |
126 | private static final String PORT_NAME = "portName"; | 140 | private static final String PORT_NAME = "portName"; |
127 | private static final String PORTNAME_PREFIX_VM = "tap"; | 141 | private static final String PORTNAME_PREFIX_VM = "tap"; |
... | @@ -134,18 +148,6 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -134,18 +148,6 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
134 | private static final int TP_PORT_MINIMUM_NUM = 1024; | 148 | private static final int TP_PORT_MINIMUM_NUM = 1024; |
135 | private static final int TP_PORT_MAXIMUM_NUM = 65535; | 149 | private static final int TP_PORT_MAXIMUM_NUM = 65535; |
136 | 150 | ||
137 | - private final ConfigFactory configFactory = | ||
138 | - new ConfigFactory(OpenstackSubjectFactories.USER_DEFINED_SUBJECT_FACTORY, OpenstackNetworkingConfig.class, | ||
139 | - "config") { | ||
140 | - @Override | ||
141 | - public OpenstackNetworkingConfig createConfig() { | ||
142 | - return new OpenstackNetworkingConfig(); | ||
143 | - } | ||
144 | - }; | ||
145 | - | ||
146 | - private final NetworkConfigListener configListener = new InternalConfigListener(); | ||
147 | - | ||
148 | - private OpenstackNetworkingConfig config; | ||
149 | private static final KryoNamespace.Builder FLOATING_IP_SERIALIZER = KryoNamespace.newBuilder() | 151 | private static final KryoNamespace.Builder FLOATING_IP_SERIALIZER = KryoNamespace.newBuilder() |
150 | .register(KryoNamespaces.API) | 152 | .register(KryoNamespaces.API) |
151 | .register(OpenstackFloatingIP.FloatingIpStatus.class) | 153 | .register(OpenstackFloatingIP.FloatingIpStatus.class) |
... | @@ -158,7 +160,8 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -158,7 +160,8 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
158 | .register(KryoNamespaces.API); | 160 | .register(KryoNamespaces.API); |
159 | 161 | ||
160 | private InternalPacketProcessor internalPacketProcessor = new InternalPacketProcessor(); | 162 | private InternalPacketProcessor internalPacketProcessor = new InternalPacketProcessor(); |
161 | - private InternalDeviceListener internalDeviceListener = new InternalDeviceListener(); | 163 | + private InternalHostListener internalHostListener = new InternalHostListener(); |
164 | + private InternalOpenstackNodeListener internalNodeListener = new InternalOpenstackNodeListener(); | ||
162 | private ExecutorService l3EventExecutorService = | 165 | private ExecutorService l3EventExecutorService = |
163 | Executors.newSingleThreadExecutor(groupedThreads("onos/openstackrouting", "L3-event")); | 166 | Executors.newSingleThreadExecutor(groupedThreads("onos/openstackrouting", "L3-event")); |
164 | private ExecutorService icmpEventExecutorService = | 167 | private ExecutorService icmpEventExecutorService = |
... | @@ -168,15 +171,16 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -168,15 +171,16 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
168 | private OpenstackIcmpHandler openstackIcmpHandler; | 171 | private OpenstackIcmpHandler openstackIcmpHandler; |
169 | private OpenstackRoutingArpHandler openstackArpHandler; | 172 | private OpenstackRoutingArpHandler openstackArpHandler; |
170 | private OpenstackRoutingRulePopulator rulePopulator; | 173 | private OpenstackRoutingRulePopulator rulePopulator; |
171 | - private Map<DeviceId, Ip4Address> computeNodeMap; | 174 | + |
175 | + private HostProviderService hostProviderService; | ||
176 | + private final HostProvider hostProvider = new InternalHostProvider(); | ||
172 | 177 | ||
173 | @Activate | 178 | @Activate |
174 | protected void activate() { | 179 | protected void activate() { |
175 | appId = coreService.registerApplication(APP_ID); | 180 | appId = coreService.registerApplication(APP_ID); |
176 | - packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1)); | 181 | + hostService.addListener(internalHostListener); |
177 | - configRegistry.registerConfigFactory(configFactory); | 182 | + nodeService.addListener(internalNodeListener); |
178 | - configService.addListener(configListener); | 183 | + hostProviderService = hostProviderRegistry.register(hostProvider); |
179 | - deviceService.addListener(internalDeviceListener); | ||
180 | 184 | ||
181 | floatingIpMap = storageService.<String, OpenstackFloatingIP>consistentMapBuilder() | 185 | floatingIpMap = storageService.<String, OpenstackFloatingIP>consistentMapBuilder() |
182 | .withSerializer(Serializer.using(FLOATING_IP_SERIALIZER.build())) | 186 | .withSerializer(Serializer.using(FLOATING_IP_SERIALIZER.build())) |
... | @@ -194,15 +198,15 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -194,15 +198,15 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
194 | .withApplicationId(appId) | 198 | .withApplicationId(appId) |
195 | .build(); | 199 | .build(); |
196 | 200 | ||
197 | - readConfiguration(); | ||
198 | - | ||
199 | log.info("started"); | 201 | log.info("started"); |
200 | } | 202 | } |
201 | 203 | ||
202 | @Deactivate | 204 | @Deactivate |
203 | protected void deactivate() { | 205 | protected void deactivate() { |
204 | packetService.removeProcessor(internalPacketProcessor); | 206 | packetService.removeProcessor(internalPacketProcessor); |
205 | - deviceService.removeListener(internalDeviceListener); | 207 | + hostService.removeListener(internalHostListener); |
208 | + nodeService.removeListener(internalNodeListener); | ||
209 | + | ||
206 | l3EventExecutorService.shutdown(); | 210 | l3EventExecutorService.shutdown(); |
207 | icmpEventExecutorService.shutdown(); | 211 | icmpEventExecutorService.shutdown(); |
208 | arpEventExecutorService.shutdown(); | 212 | arpEventExecutorService.shutdown(); |
... | @@ -228,20 +232,27 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -228,20 +232,27 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
228 | } | 232 | } |
229 | if (openstackFloatingIp.portId() == null || openstackFloatingIp.portId().equals("null")) { | 233 | if (openstackFloatingIp.portId() == null || openstackFloatingIp.portId().equals("null")) { |
230 | OpenstackFloatingIP floatingIp = floatingIpMap.get(openstackFloatingIp.id()).value(); | 234 | OpenstackFloatingIP floatingIp = floatingIpMap.get(openstackFloatingIp.id()).value(); |
231 | - OpenstackPortInfo portInfo = openstackSwitchingService.openstackPortInfo() | 235 | + // XXX When the VM has been removed, host information has been removed or not ??? |
232 | - .get(PORTNAME_PREFIX_VM.concat(floatingIp.portId().substring(0, 11))); | 236 | + Optional<Host> host = hostService.getHostsByIp(openstackFloatingIp.fixedIpAddress().getIp4Address()) |
233 | - if (portInfo == null) { | 237 | + .stream() |
234 | - log.warn("There`s no portInfo information about portId {}", floatingIp.portId()); | 238 | + .findFirst(); |
239 | + if (!host.isPresent()) { | ||
240 | + log.warn("No Host info with the VM IP the Floating IP address {} is found", | ||
241 | + openstackFloatingIp.floatingIpAddress()); | ||
235 | return; | 242 | return; |
236 | } | 243 | } |
237 | l3EventExecutorService.execute( | 244 | l3EventExecutorService.execute( |
238 | - new OpenstackFloatingIPHandler(rulePopulator, floatingIp, false, portInfo)); | 245 | + new OpenstackFloatingIPHandler(rulePopulator, floatingIp, Action.DISSASSOCIATE, host.get())); |
239 | floatingIpMap.replace(floatingIp.id(), openstackFloatingIp); | 246 | floatingIpMap.replace(floatingIp.id(), openstackFloatingIp); |
247 | + registerFloatingIpToHostService(openstackFloatingIp, Action.DISSASSOCIATE); | ||
240 | } else { | 248 | } else { |
241 | floatingIpMap.put(openstackFloatingIp.id(), openstackFloatingIp); | 249 | floatingIpMap.put(openstackFloatingIp.id(), openstackFloatingIp); |
242 | l3EventExecutorService.execute( | 250 | l3EventExecutorService.execute( |
243 | - new OpenstackFloatingIPHandler(rulePopulator, openstackFloatingIp, true, null)); | 251 | + new OpenstackFloatingIPHandler(rulePopulator, openstackFloatingIp, Action.ASSOCIATE, null)); |
252 | + registerFloatingIpToHostService(openstackFloatingIp, Action.ASSOCIATE); | ||
244 | } | 253 | } |
254 | + | ||
255 | + | ||
245 | } | 256 | } |
246 | 257 | ||
247 | @Override | 258 | @Override |
... | @@ -356,6 +367,10 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -356,6 +367,10 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
356 | 367 | ||
357 | private void removeL3RulesForRouterInterface(OpenstackRouterInterface routerInterface, OpenstackRouter router, | 368 | private void removeL3RulesForRouterInterface(OpenstackRouterInterface routerInterface, OpenstackRouter router, |
358 | List<OpenstackRouterInterface> newList) { | 369 | List<OpenstackRouterInterface> newList) { |
370 | + if (!routerInterfaceMap.containsKey(routerInterface.portId())) { | ||
371 | + log.warn("No router interface information found for {}", routerInterface.portId()); | ||
372 | + return; | ||
373 | + } | ||
359 | openstackService.ports(routerInterfaceMap.get(routerInterface.portId()).value()).forEach(p -> { | 374 | openstackService.ports(routerInterfaceMap.get(routerInterface.portId()).value()).forEach(p -> { |
360 | Ip4Address vmIp = (Ip4Address) p.fixedIps().values().toArray()[0]; | 375 | Ip4Address vmIp = (Ip4Address) p.fixedIps().values().toArray()[0]; |
361 | if (newList == null) { | 376 | if (newList == null) { |
... | @@ -368,6 +383,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -368,6 +383,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
368 | ); | 383 | ); |
369 | } | 384 | } |
370 | 385 | ||
386 | + /* | ||
371 | @Override | 387 | @Override |
372 | public void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo) { | 388 | public void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo) { |
373 | if (floatingIpMap.size() < 1) { | 389 | if (floatingIpMap.size() < 1) { |
... | @@ -393,6 +409,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -393,6 +409,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
393 | log.warn("portInfo is null as timing issue between ovs port update event and openstack deletePort event"); | 409 | log.warn("portInfo is null as timing issue between ovs port update event and openstack deletePort event"); |
394 | } | 410 | } |
395 | } | 411 | } |
412 | + */ | ||
396 | 413 | ||
397 | @Override | 414 | @Override |
398 | public String networkIdForRouterInterface(String portId) { | 415 | public String networkIdForRouterInterface(String portId) { |
... | @@ -445,6 +462,11 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -445,6 +462,11 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
445 | @Override | 462 | @Override |
446 | public void process(PacketContext context) { | 463 | public void process(PacketContext context) { |
447 | 464 | ||
465 | + DeviceId senderDeviceId = context.inPacket().receivedFrom().deviceId(); | ||
466 | + if (!nodeService.routerBridge(senderDeviceId).isPresent()) { | ||
467 | + log.warn("No router bridge for {} is found.", senderDeviceId); | ||
468 | + return; | ||
469 | + } | ||
448 | if (context.isHandled()) { | 470 | if (context.isHandled()) { |
449 | return; | 471 | return; |
450 | } else if (!checkGatewayNode(context.inPacket().receivedFrom().deviceId())) { | 472 | } else if (!checkGatewayNode(context.inPacket().receivedFrom().deviceId())) { |
... | @@ -482,7 +504,8 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -482,7 +504,8 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
482 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), | 504 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), |
483 | Ip4Address.valueOf(iPacket.getSourceAddress())); | 505 | Ip4Address.valueOf(iPacket.getSourceAddress())); |
484 | l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, | 506 | l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, |
485 | - portNum, openstackPort, port, config)); | 507 | + portNum, openstackPort, port)); |
508 | + | ||
486 | } else { | 509 | } else { |
487 | log.warn("There`s no external interface"); | 510 | log.warn("There`s no external interface"); |
488 | } | 511 | } |
... | @@ -602,75 +625,166 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -602,75 +625,166 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
602 | return null; | 625 | return null; |
603 | } | 626 | } |
604 | 627 | ||
605 | - private void readConfiguration() { | 628 | + private Optional<OpenstackPort> getRouterInterfacePort(String networkId) { |
606 | - config = configService.getConfig("openstacknetworking", OpenstackNetworkingConfig.class); | 629 | + |
607 | - if (config == null) { | 630 | + return openstackService.ports() |
608 | - log.error("No configuration found"); | 631 | + .stream() |
632 | + .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE) | ||
633 | + && p.networkId().equals(networkId)) | ||
634 | + .findAny(); | ||
635 | + } | ||
636 | + | ||
637 | + // TODO: Remove the function and the related codes when vRouter is running on different ONOS instance. | ||
638 | + private void registerFloatingIpToHostService(OpenstackFloatingIP openstackFloatingIp, Action action) { | ||
639 | + | ||
640 | + Optional<Host> hostOptional = hostService.getHostsByIp(openstackFloatingIp.fixedIpAddress()) | ||
641 | + .stream() | ||
642 | + .findFirst(); | ||
643 | + if (!hostOptional.isPresent()) { | ||
644 | + log.warn("No host with IP {} is registered and cannot add the floating IP. ", | ||
645 | + openstackFloatingIp.floatingIpAddress()); | ||
609 | return; | 646 | return; |
610 | } | 647 | } |
611 | 648 | ||
612 | - rulePopulator = new OpenstackRoutingRulePopulator(appId, openstackService, flowObjectiveService, | 649 | + Host host = hostOptional.get(); |
613 | - deviceService, driverService, config, gatewayService); | 650 | + Set<IpAddress> ipAddresses = Sets.newHashSet(); |
614 | - openstackIcmpHandler = new OpenstackIcmpHandler(packetService, deviceService, | 651 | + if (action == Action.ASSOCIATE) { |
615 | - openstackService, config, openstackSwitchingService, gatewayService); | 652 | + ipAddresses.add(openstackFloatingIp.floatingIpAddress()); |
616 | - openstackArpHandler = new OpenstackRoutingArpHandler(packetService, openstackService, | 653 | + } |
617 | - config, gatewayService); | ||
618 | - openstackIcmpHandler.requestPacket(appId); | ||
619 | - openstackArpHandler.requestPacket(appId); | ||
620 | - | ||
621 | - openstackService.floatingIps().stream() | ||
622 | - .forEach(f -> floatingIpMap.put(f.id(), f)); | ||
623 | 654 | ||
624 | - reloadInitL3Rules(); | 655 | + HostDescription hostDescription = |
656 | + new DefaultHostDescription(host.mac(), host.vlan(), host.location(), ipAddresses, | ||
657 | + (DefaultAnnotations) host.annotations()); | ||
625 | 658 | ||
626 | - log.info("OpenstackRouting configured"); | 659 | + hostProviderService.hostDetected(host.id(), hostDescription, false); |
627 | } | 660 | } |
628 | 661 | ||
629 | - private class InternalConfigListener implements NetworkConfigListener { | 662 | + private class InternalHostListener implements HostListener { |
663 | + | ||
664 | + private void hostDetected(Host host) { | ||
665 | + | ||
666 | + String portId = host.annotations().value(Constants.PORT_ID); | ||
667 | + OpenstackPort openstackPort = openstackService.port(portId); | ||
668 | + if (openstackPort == null) { | ||
669 | + log.warn("No OpenstackPort information found from OpenStack for port ID {}", portId); | ||
670 | + return; | ||
671 | + } | ||
672 | + | ||
673 | + Optional<OpenstackPort> routerPort = getRouterInterfacePort(openstackPort.networkId()); | ||
674 | + if (routerPort.isPresent()) { | ||
675 | + OpenstackRouterInterface routerInterface = portToRouterInterface(routerPort.get()); | ||
676 | + l3EventExecutorService.execute(() -> | ||
677 | + setL3Connection(getOpenstackRouter(routerInterface.id()), openstackPort)); | ||
678 | + | ||
679 | + } | ||
680 | + } | ||
681 | + | ||
682 | + private void hostRemoved(Host host) { | ||
683 | + String portId = host.annotations().value(Constants.PORT_ID); | ||
684 | + OpenstackPort openstackPort = openstackService.port(portId); | ||
685 | + if (openstackPort == null) { | ||
686 | + log.warn("No OpenstackPort information found from OpenStack for port ID {}", portId); | ||
687 | + return; | ||
688 | + } | ||
689 | + | ||
690 | + Optional<OpenstackPort> routerPort = getRouterInterfacePort(openstackPort.networkId()); | ||
691 | + if (routerPort.isPresent()) { | ||
692 | + OpenstackRouterInterface routerInterface = portToRouterInterface(routerPort.get()); | ||
693 | + IpAddress ipAddress = host.ipAddresses().stream().findFirst().get(); | ||
694 | + l3EventExecutorService.execute(() -> rulePopulator.removeL3Rules(ipAddress.getIp4Address(), | ||
695 | + getL3ConnectionList(host.annotations().value(Constants.NETWORK_ID), | ||
696 | + getOpenstackRouterInterface(getOpenstackRouter(routerInterface.id()))))); | ||
697 | + } | ||
698 | + } | ||
699 | + | ||
700 | + private boolean isValidHost(Host host) { | ||
701 | + return !host.ipAddresses().isEmpty() && | ||
702 | + host.annotations().value(Constants.VXLAN_ID) != null && | ||
703 | + host.annotations().value(Constants.NETWORK_ID) != null && | ||
704 | + host.annotations().value(Constants.TENANT_ID) != null && | ||
705 | + host.annotations().value(Constants.PORT_ID) != null; | ||
706 | + } | ||
630 | 707 | ||
631 | @Override | 708 | @Override |
632 | - public void event(NetworkConfigEvent event) { | 709 | + public void event(HostEvent event) { |
633 | - if (!event.configClass().equals(OpenstackNetworkingConfig.class)) { | 710 | + Host host = event.subject(); |
711 | + if (!mastershipService.isLocalMaster(host.location().deviceId())) { | ||
712 | + // do not allow to proceed without mastership | ||
634 | return; | 713 | return; |
635 | } | 714 | } |
636 | 715 | ||
637 | - if (event.type().equals(NetworkConfigEvent.Type.CONFIG_ADDED) || | 716 | + if (!isValidHost(host)) { |
638 | - event.type().equals(NetworkConfigEvent.Type.CONFIG_UPDATED)) { | 717 | + log.debug("Invalid host event, ignore it {}", host); |
639 | - l3EventExecutorService.execute(OpenstackRoutingManager.this::readConfiguration); | 718 | + return; |
719 | + } | ||
720 | + | ||
721 | + switch (event.type()) { | ||
722 | + case HOST_UPDATED: | ||
723 | + case HOST_ADDED: | ||
724 | + l3EventExecutorService.execute(() -> hostDetected(host)); | ||
725 | + break; | ||
726 | + case HOST_REMOVED: | ||
727 | + l3EventExecutorService.execute(() -> hostRemoved(host)); | ||
728 | + break; | ||
729 | + default: | ||
730 | + break; | ||
640 | } | 731 | } |
641 | } | 732 | } |
642 | } | 733 | } |
643 | 734 | ||
644 | - private class InternalDeviceListener implements DeviceListener { | 735 | + private class InternalOpenstackNodeListener implements OpenstackNodeListener { |
736 | + | ||
737 | + private void nodeComplete() { | ||
738 | + | ||
739 | + rulePopulator = new OpenstackRoutingRulePopulator(appId, openstackService, flowObjectiveService, | ||
740 | + deviceService, driverService, nodeService, gatewayService); | ||
741 | + openstackIcmpHandler = new OpenstackIcmpHandler(packetService, deviceService, hostService, | ||
742 | + openstackService, nodeService, gatewayService); | ||
743 | + openstackArpHandler = new OpenstackRoutingArpHandler(packetService, openstackService, nodeService, | ||
744 | + gatewayService); | ||
745 | + | ||
746 | + // Packet handlers must be started AFTER all initialization processes. | ||
747 | + packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1)); | ||
748 | + | ||
749 | + openstackIcmpHandler.requestPacket(appId); | ||
750 | + openstackArpHandler.requestPacket(appId); | ||
751 | + | ||
752 | + openstackService.floatingIps().stream() | ||
753 | + .forEach(f -> floatingIpMap.put(f.id(), f)); | ||
754 | + | ||
755 | + reloadInitL3Rules(); | ||
756 | + } | ||
645 | 757 | ||
646 | @Override | 758 | @Override |
647 | - public void event(DeviceEvent deviceEvent) { | 759 | + public void event(OpenstackNodeEvent event) { |
648 | - if (deviceEvent.type() == DeviceEvent.Type.PORT_UPDATED) { | 760 | + OpenstackNode node = event.node(); |
649 | - Port port = deviceEvent.port(); | 761 | + |
650 | - OpenstackPortInfo portInfo = openstackSwitchingService.openstackPortInfo() | 762 | + switch (event.type()) { |
651 | - .get(port.annotations().value(PORT_NAME)); | 763 | + case COMPLETE: |
652 | - OpenstackPort openstackPort = openstackService.port(port); | 764 | + log.info("COMPLETE node {} detected", node.hostname()); |
653 | - OpenstackPort interfacePort = openstackService.ports() | 765 | + l3EventExecutorService.execute(() -> nodeComplete()); |
654 | - .stream() | 766 | + break; |
655 | - .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE) | 767 | + case INCOMPLETE: |
656 | - && p.networkId().equals(openstackPort.networkId())) | 768 | + break; |
657 | - .findAny() | 769 | + default: |
658 | - .orElse(null); | 770 | + break; |
659 | - if (portInfo == null && openstackPort == null) { | ||
660 | - log.warn("As delete event timing issue between routing and switching, Can`t delete L3 rules"); | ||
661 | - return; | ||
662 | - } | ||
663 | - if ((port.isEnabled()) && (interfacePort != null)) { | ||
664 | - OpenstackRouterInterface routerInterface = portToRouterInterface(interfacePort); | ||
665 | - l3EventExecutorService.execute(() -> | ||
666 | - setL3Connection(getOpenstackRouter(routerInterface.id()), openstackPort)); | ||
667 | - } else if (interfacePort != null) { | ||
668 | - OpenstackRouterInterface routerInterface = portToRouterInterface(interfacePort); | ||
669 | - l3EventExecutorService.execute(() -> rulePopulator.removeL3Rules(portInfo.ip(), | ||
670 | - getL3ConnectionList(portInfo.networkId(), | ||
671 | - getOpenstackRouterInterface(getOpenstackRouter(routerInterface.id()))))); | ||
672 | - } | ||
673 | } | 771 | } |
772 | + | ||
773 | + } | ||
774 | + } | ||
775 | + | ||
776 | + private class InternalHostProvider extends AbstractProvider implements HostProvider { | ||
777 | + | ||
778 | + /** | ||
779 | + * Creates a provider with the supplier identifier. | ||
780 | + */ | ||
781 | + protected InternalHostProvider() { | ||
782 | + super(PID); | ||
783 | + } | ||
784 | + | ||
785 | + @Override | ||
786 | + public void triggerProbe(Host host) { | ||
787 | + // nothing to do | ||
674 | } | 788 | } |
675 | } | 789 | } |
676 | 790 | ... | ... |
... | @@ -29,6 +29,7 @@ import org.onosproject.core.ApplicationId; | ... | @@ -29,6 +29,7 @@ import org.onosproject.core.ApplicationId; |
29 | import org.onosproject.core.GroupId; | 29 | import org.onosproject.core.GroupId; |
30 | import org.onosproject.net.Device; | 30 | import org.onosproject.net.Device; |
31 | import org.onosproject.net.DeviceId; | 31 | import org.onosproject.net.DeviceId; |
32 | +import org.onosproject.net.Host; | ||
32 | import org.onosproject.net.Port; | 33 | import org.onosproject.net.Port; |
33 | import org.onosproject.net.PortNumber; | 34 | import org.onosproject.net.PortNumber; |
34 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; | 35 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
... | @@ -54,14 +55,16 @@ import org.onosproject.openstackinterface.OpenstackPort; | ... | @@ -54,14 +55,16 @@ import org.onosproject.openstackinterface.OpenstackPort; |
54 | import org.onosproject.openstackinterface.OpenstackRouterInterface; | 55 | import org.onosproject.openstackinterface.OpenstackRouterInterface; |
55 | import org.onosproject.openstackinterface.OpenstackSubnet; | 56 | import org.onosproject.openstackinterface.OpenstackSubnet; |
56 | import org.onosproject.openstackinterface.OpenstackFloatingIP; | 57 | import org.onosproject.openstackinterface.OpenstackFloatingIP; |
57 | -import org.onosproject.openstacknetworking.OpenstackNetworkingConfig; | 58 | +import org.onosproject.openstacknetworking.Constants; |
58 | -import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
59 | import org.onosproject.openstacknetworking.OpenstackRoutingService; | 59 | import org.onosproject.openstacknetworking.OpenstackRoutingService; |
60 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 60 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
61 | +import org.onosproject.openstacknode.OpenstackNode; | ||
62 | +import org.onosproject.openstacknode.OpenstackNodeService; | ||
61 | import org.slf4j.Logger; | 63 | import org.slf4j.Logger; |
62 | import org.slf4j.LoggerFactory; | 64 | import org.slf4j.LoggerFactory; |
63 | 65 | ||
64 | import java.util.List; | 66 | import java.util.List; |
67 | +import java.util.Optional; | ||
65 | import java.util.stream.StreamSupport; | 68 | import java.util.stream.StreamSupport; |
66 | 69 | ||
67 | import static com.google.common.base.Preconditions.checkNotNull; | 70 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -79,8 +82,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -79,8 +82,8 @@ public class OpenstackRoutingRulePopulator { |
79 | private final OpenstackInterfaceService openstackService; | 82 | private final OpenstackInterfaceService openstackService; |
80 | private final DeviceService deviceService; | 83 | private final DeviceService deviceService; |
81 | private final DriverService driverService; | 84 | private final DriverService driverService; |
82 | - private final OpenstackNetworkingConfig config; | ||
83 | private final ScalableGatewayService gatewayService; | 85 | private final ScalableGatewayService gatewayService; |
86 | + private final OpenstackNodeService nodeService; | ||
84 | 87 | ||
85 | private static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; | 88 | private static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; |
86 | private static final String PORTNAME = "portName"; | 89 | private static final String PORTNAME = "portName"; |
... | @@ -95,7 +98,6 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -95,7 +98,6 @@ public class OpenstackRoutingRulePopulator { |
95 | private static final int PNAT_RULE_PRIORITY = 26000; | 98 | private static final int PNAT_RULE_PRIORITY = 26000; |
96 | private static final int PNAT_TIMEOUT = 120; | 99 | private static final int PNAT_TIMEOUT = 120; |
97 | private static final int PREFIX_LENGTH = 32; | 100 | private static final int PREFIX_LENGTH = 32; |
98 | - private static final MacAddress GATEWAYMAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); | ||
99 | 101 | ||
100 | private InboundPacket inboundPacket; | 102 | private InboundPacket inboundPacket; |
101 | private OpenstackPort openstackPort; | 103 | private OpenstackPort openstackPort; |
... | @@ -111,20 +113,22 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -111,20 +113,22 @@ public class OpenstackRoutingRulePopulator { |
111 | * @param flowObjectiveService FlowObjectiveService | 113 | * @param flowObjectiveService FlowObjectiveService |
112 | * @param deviceService DeviceService | 114 | * @param deviceService DeviceService |
113 | * @param driverService DriverService | 115 | * @param driverService DriverService |
114 | - * @param config Configuration for openstack environment | ||
115 | * @param gatewayService scalable gateway service | 116 | * @param gatewayService scalable gateway service |
116 | */ | 117 | */ |
117 | - public OpenstackRoutingRulePopulator(ApplicationId appId, OpenstackInterfaceService openstackService, | 118 | + public OpenstackRoutingRulePopulator(ApplicationId appId, |
118 | - FlowObjectiveService flowObjectiveService, DeviceService deviceService, | 119 | + OpenstackInterfaceService openstackService, |
119 | - DriverService driverService, OpenstackNetworkingConfig config, | 120 | + FlowObjectiveService flowObjectiveService, |
121 | + DeviceService deviceService, | ||
122 | + DriverService driverService, | ||
123 | + OpenstackNodeService nodeService, | ||
120 | ScalableGatewayService gatewayService) { | 124 | ScalableGatewayService gatewayService) { |
121 | this.appId = appId; | 125 | this.appId = appId; |
122 | this.flowObjectiveService = flowObjectiveService; | 126 | this.flowObjectiveService = flowObjectiveService; |
123 | this.openstackService = checkNotNull(openstackService); | 127 | this.openstackService = checkNotNull(openstackService); |
124 | this.deviceService = deviceService; | 128 | this.deviceService = deviceService; |
125 | this.driverService = driverService; | 129 | this.driverService = driverService; |
126 | - this.config = config; | ||
127 | this.gatewayService = gatewayService; | 130 | this.gatewayService = gatewayService; |
131 | + this.nodeService = nodeService; | ||
128 | } | 132 | } |
129 | 133 | ||
130 | /** | 134 | /** |
... | @@ -201,7 +205,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -201,7 +205,8 @@ public class OpenstackRoutingRulePopulator { |
201 | 205 | ||
202 | private Port getPortOfExternalInterface() { | 206 | private Port getPortOfExternalInterface() { |
203 | return deviceService.getPorts(getGatewayNode().id()).stream() | 207 | return deviceService.getPorts(getGatewayNode().id()).stream() |
204 | - .filter(p -> p.annotations().value(PORTNAME).equals(config.gatewayExternalInterfaceName())) | 208 | + .filter(p -> p.annotations().value(PORTNAME) |
209 | + .equals(org.onosproject.openstacknode.Constants.PATCH_INTG_BRIDGE)) | ||
205 | .findAny().orElse(null); | 210 | .findAny().orElse(null); |
206 | } | 211 | } |
207 | 212 | ||
... | @@ -239,7 +244,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -239,7 +244,8 @@ public class OpenstackRoutingRulePopulator { |
239 | 244 | ||
240 | getGatewayNodeList().forEach(node -> { | 245 | getGatewayNodeList().forEach(node -> { |
241 | DeviceId deviceId = node.id(); | 246 | DeviceId deviceId = node.id(); |
242 | - tBuilder.extension(buildNiciraExtenstion(deviceId, getHostIpfromOpenstackPort(openstackPort)), deviceId) | 247 | + tBuilder.extension(buildNiciraExtenstion(deviceId, |
248 | + getHostIpfromOpenstackPort(openstackPort).getIp4Address()), deviceId) | ||
243 | .setOutput(getTunnelPort(deviceId)); | 249 | .setOutput(getTunnelPort(deviceId)); |
244 | 250 | ||
245 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 251 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
... | @@ -262,9 +268,16 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -262,9 +268,16 @@ public class OpenstackRoutingRulePopulator { |
262 | return devices; | 268 | return devices; |
263 | } | 269 | } |
264 | 270 | ||
265 | - private Ip4Address getHostIpfromOpenstackPort(OpenstackPort openstackPort) { | 271 | + private IpAddress getHostIpfromOpenstackPort(OpenstackPort openstackPort) { |
266 | Device device = getDevicefromOpenstackPort(openstackPort); | 272 | Device device = getDevicefromOpenstackPort(openstackPort); |
267 | - return config.nodes().get(device.id()); | 273 | + |
274 | + Optional<IpAddress> ipAddress = nodeService.dataIp(device.id()); | ||
275 | + if (!ipAddress.isPresent()) { | ||
276 | + log.warn("No IP address found for device {}", device.id()); | ||
277 | + return null; | ||
278 | + } | ||
279 | + | ||
280 | + return ipAddress.get(); | ||
268 | } | 281 | } |
269 | 282 | ||
270 | private Device getDevicefromOpenstackPort(OpenstackPort openstackPort) { | 283 | private Device getDevicefromOpenstackPort(OpenstackPort openstackPort) { |
... | @@ -349,7 +362,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -349,7 +362,7 @@ public class OpenstackRoutingRulePopulator { |
349 | 362 | ||
350 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 363 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
351 | .matchTunnelId(vni) | 364 | .matchTunnelId(vni) |
352 | - .matchEthDst(GATEWAYMAC); | 365 | + .matchEthDst(Constants.GATEWAY_MAC); |
353 | tBuilder.setOutput(PortNumber.CONTROLLER); | 366 | tBuilder.setOutput(PortNumber.CONTROLLER); |
354 | 367 | ||
355 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 368 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
... | @@ -365,7 +378,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -365,7 +378,7 @@ public class OpenstackRoutingRulePopulator { |
365 | 378 | ||
366 | private void populateComputeNodeRules(long vni) { | 379 | private void populateComputeNodeRules(long vni) { |
367 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) | 380 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
368 | - .filter(d -> !checkGatewayNode(d.id())) | 381 | + .filter(d -> isTypeOf(d.id(), OpenstackNodeService.NodeType.COMPUTE)) |
369 | .forEach(d -> populateRuleToGatewayBySgw(d.id(), | 382 | .forEach(d -> populateRuleToGatewayBySgw(d.id(), |
370 | gatewayService.getGroupIdForGatewayLoadBalance(d.id()), vni)); | 383 | gatewayService.getGroupIdForGatewayLoadBalance(d.id()), vni)); |
371 | } | 384 | } |
... | @@ -376,7 +389,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -376,7 +389,8 @@ public class OpenstackRoutingRulePopulator { |
376 | 389 | ||
377 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 390 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
378 | .matchTunnelId(vni) | 391 | .matchTunnelId(vni) |
379 | - .matchEthDst(GATEWAYMAC); | 392 | + .matchEthDst(Constants.GATEWAY_MAC); |
393 | + | ||
380 | tBuilder.group(groupId); | 394 | tBuilder.group(groupId); |
381 | 395 | ||
382 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 396 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
... | @@ -390,14 +404,15 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -390,14 +404,15 @@ public class OpenstackRoutingRulePopulator { |
390 | flowObjectiveService.forward(deviceId, fo); | 404 | flowObjectiveService.forward(deviceId, fo); |
391 | } | 405 | } |
392 | 406 | ||
407 | + /* | ||
393 | private void populateRuleToGateway(DeviceId deviceId, Device gatewayDevice, long vni) { | 408 | private void populateRuleToGateway(DeviceId deviceId, Device gatewayDevice, long vni) { |
394 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | 409 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
395 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | 410 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
396 | 411 | ||
397 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 412 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
398 | .matchTunnelId(vni) | 413 | .matchTunnelId(vni) |
399 | - .matchEthDst(GATEWAYMAC); | 414 | + .matchEthDst(Constants.GATEWAY_MAC); |
400 | - tBuilder.extension(buildNiciraExtenstion(deviceId, config.nodes().get(gatewayDevice.id())), deviceId) | 415 | + tBuilder.extension(buildNiciraExtenstion(deviceId, nodeService.nodes().get(gatewayDevice.id())), deviceId) |
401 | .setOutput(getTunnelPort(deviceId)); | 416 | .setOutput(getTunnelPort(deviceId)); |
402 | 417 | ||
403 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 418 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
... | @@ -410,13 +425,36 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -410,13 +425,36 @@ public class OpenstackRoutingRulePopulator { |
410 | 425 | ||
411 | flowObjectiveService.forward(deviceId, fo); | 426 | flowObjectiveService.forward(deviceId, fo); |
412 | } | 427 | } |
428 | + */ | ||
413 | 429 | ||
414 | private Device getGatewayNode() { | 430 | private Device getGatewayNode() { |
415 | - return checkNotNull(deviceService.getDevice(DeviceId.deviceId(config.gatewayBridgeId()))); | 431 | + |
432 | + // TODO Return the correct gateway node | ||
433 | + Optional<OpenstackNode> gwNode = nodeService.nodes().stream() | ||
434 | + .filter(n -> n.type().equals(OpenstackNodeService.NodeType.GATEWAY)) | ||
435 | + .findFirst(); | ||
436 | + | ||
437 | + if (!gwNode.isPresent()) { | ||
438 | + log.warn("No Gateway is defined."); | ||
439 | + return null; | ||
440 | + } | ||
441 | + | ||
442 | + return deviceService.getDevice(gwNode.get().intBridge()); | ||
416 | } | 443 | } |
417 | 444 | ||
418 | - private boolean checkGatewayNode(DeviceId deviceId) { | 445 | + private boolean isTypeOf(DeviceId deviceId, OpenstackNodeService.NodeType type) { |
419 | - return gatewayService.getGatewayDeviceIds().stream().anyMatch(dId -> dId.equals(deviceId)); | 446 | + |
447 | + Optional<OpenstackNode> node = nodeService.nodes().stream() | ||
448 | + .filter(n -> n.intBridge().equals(deviceId) || | ||
449 | + (n.routerBridge().isPresent() && n.routerBridge().get().equals(deviceId))) | ||
450 | + .filter(n -> n.type().equals(type)) | ||
451 | + .findFirst(); | ||
452 | + | ||
453 | + if (node.isPresent()) { | ||
454 | + return true; | ||
455 | + } | ||
456 | + | ||
457 | + return false; | ||
420 | } | 458 | } |
421 | 459 | ||
422 | private long getVni(String netId) { | 460 | private long getVni(String netId) { |
... | @@ -433,11 +471,11 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -433,11 +471,11 @@ public class OpenstackRoutingRulePopulator { |
433 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | 471 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
434 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 472 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
435 | .matchTunnelId(getVni(openstackSubnet.networkId())) | 473 | .matchTunnelId(getVni(openstackSubnet.networkId())) |
436 | - .matchEthDst(GATEWAYMAC); | 474 | + .matchEthDst(Constants.GATEWAY_MAC); |
437 | 475 | ||
438 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) | 476 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
439 | .forEach(d -> { | 477 | .forEach(d -> { |
440 | - ForwardingObjective.Flag flag = checkGatewayNode(d.id()) ? | 478 | + ForwardingObjective.Flag flag = isTypeOf(d.id(), OpenstackNodeService.NodeType.GATEWAY) ? |
441 | ForwardingObjective.Flag.VERSATILE : | 479 | ForwardingObjective.Flag.VERSATILE : |
442 | ForwardingObjective.Flag.SPECIFIC; | 480 | ForwardingObjective.Flag.SPECIFIC; |
443 | removeRule(d.id(), sBuilder, flag, ROUTING_RULE_PRIORITY); | 481 | removeRule(d.id(), sBuilder, flag, ROUTING_RULE_PRIORITY); |
... | @@ -474,33 +512,35 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -474,33 +512,35 @@ public class OpenstackRoutingRulePopulator { |
474 | } | 512 | } |
475 | 513 | ||
476 | private void populateFloatingIpIncomingRules(OpenstackFloatingIP floatingIP, OpenstackPort port) { | 514 | private void populateFloatingIpIncomingRules(OpenstackFloatingIP floatingIP, OpenstackPort port) { |
477 | - DeviceId portDeviceId = getDevicefromOpenstackPort(port).id(); | ||
478 | - | ||
479 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | 515 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
480 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | 516 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
481 | 517 | ||
482 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 518 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
483 | .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), PREFIX_LENGTH)); | 519 | .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), PREFIX_LENGTH)); |
484 | 520 | ||
485 | - getGatewayNodeList().forEach(device -> { | 521 | + DeviceId gatewayDeviceId = DeviceId.deviceId(port.deviceId()); |
486 | - DeviceId deviceId = device.id(); | 522 | + Optional<IpAddress> ipAddress = nodeService.dataIp(gatewayDeviceId); |
487 | - tBuilder.setEthSrc(GATEWAYMAC) | 523 | + if (!ipAddress.isPresent()) { |
488 | - .setEthDst(port.macAddress()) | 524 | + log.warn("No IP address found for device {}", port.deviceId()); |
489 | - .setIpDst(floatingIP.fixedIpAddress()) | 525 | + return; |
490 | - .setTunnelId(getVni(port.networkId())) | 526 | + } |
491 | - .extension(buildNiciraExtenstion(deviceId, config.nodes().get(portDeviceId)), deviceId) | 527 | + tBuilder.setEthSrc(Constants.GATEWAY_MAC) |
492 | - .setOutput(getTunnelPort(deviceId)); | 528 | + .setEthDst(port.macAddress()) |
529 | + .setIpDst(floatingIP.fixedIpAddress()) | ||
530 | + .setTunnelId(getVni(port.networkId())) | ||
531 | + .extension(buildNiciraExtenstion(gatewayDeviceId, | ||
532 | + ipAddress.get().getIp4Address()), gatewayDeviceId) | ||
533 | + .setOutput(getTunnelPort(gatewayDeviceId)); | ||
493 | 534 | ||
494 | - ForwardingObjective fo = DefaultForwardingObjective.builder() | 535 | + ForwardingObjective fo = DefaultForwardingObjective.builder() |
495 | - .withSelector(sBuilder.build()) | 536 | + .withSelector(sBuilder.build()) |
496 | - .withTreatment(tBuilder.build()) | 537 | + .withTreatment(tBuilder.build()) |
497 | - .withFlag(ForwardingObjective.Flag.VERSATILE) | 538 | + .withFlag(ForwardingObjective.Flag.VERSATILE) |
498 | - .withPriority(FLOATING_RULE_PRIORITY) | 539 | + .withPriority(FLOATING_RULE_PRIORITY) |
499 | - .fromApp(appId) | 540 | + .fromApp(appId) |
500 | - .add(); | 541 | + .add(); |
501 | 542 | ||
502 | - flowObjectiveService.forward(deviceId, fo); | 543 | + flowObjectiveService.forward(getGatewayNode().id(), fo); |
503 | - }); | ||
504 | } | 544 | } |
505 | 545 | ||
506 | private void populateFloatingIpOutgoingRules(OpenstackFloatingIP floatingIP, OpenstackPort port) { | 546 | private void populateFloatingIpOutgoingRules(OpenstackFloatingIP floatingIP, OpenstackPort port) { |
... | @@ -514,6 +554,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -514,6 +554,8 @@ public class OpenstackRoutingRulePopulator { |
514 | getGatewayNodeList().forEach(device -> { | 554 | getGatewayNodeList().forEach(device -> { |
515 | DeviceId deviceId = device.id(); | 555 | DeviceId deviceId = device.id(); |
516 | tBuilder.setIpSrc(floatingIP.floatingIpAddress()) | 556 | tBuilder.setIpSrc(floatingIP.floatingIpAddress()) |
557 | + .setEthSrc(Constants.GW_EXT_INT_MAC) | ||
558 | + .setEthDst(Constants.PHY_ROUTER_MAC) | ||
517 | .setOutput(getExternalPortNum(deviceId)); | 559 | .setOutput(getExternalPortNum(deviceId)); |
518 | 560 | ||
519 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 561 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
... | @@ -535,19 +577,20 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -535,19 +577,20 @@ public class OpenstackRoutingRulePopulator { |
535 | /** | 577 | /** |
536 | * Removes flow rules for floating ip configuration. | 578 | * Removes flow rules for floating ip configuration. |
537 | * | 579 | * |
538 | - * @param floatingIP Corresponding floating ip information | 580 | + * @param floatingIp Corresponding floating ip information |
539 | - * @param portInfo stored information about deleted vm | 581 | + * @param host host information for vm to remove |
540 | */ | 582 | */ |
541 | - public void removeFloatingIpRules(OpenstackFloatingIP floatingIP, OpenstackPortInfo portInfo) { | 583 | + public void removeFloatingIpRules(OpenstackFloatingIP floatingIp, Host host) { |
542 | TrafficSelector.Builder sOutgoingBuilder = DefaultTrafficSelector.builder(); | 584 | TrafficSelector.Builder sOutgoingBuilder = DefaultTrafficSelector.builder(); |
543 | TrafficSelector.Builder sIncomingBuilder = DefaultTrafficSelector.builder(); | 585 | TrafficSelector.Builder sIncomingBuilder = DefaultTrafficSelector.builder(); |
544 | 586 | ||
587 | + // XXX FloatingIp.tenant_id() == host.vxlan_id ??? | ||
545 | sOutgoingBuilder.matchEthType(Ethernet.TYPE_IPV4) | 588 | sOutgoingBuilder.matchEthType(Ethernet.TYPE_IPV4) |
546 | - .matchTunnelId(portInfo.vni()) | 589 | + .matchTunnelId(Integer.parseInt(host.annotations().value(Constants.VXLAN_ID))) |
547 | - .matchIPSrc(IpPrefix.valueOf(portInfo.ip(), PREFIX_LENGTH)); | 590 | + .matchIPSrc(IpPrefix.valueOf(floatingIp.fixedIpAddress(), PREFIX_LENGTH)); |
548 | 591 | ||
549 | sIncomingBuilder.matchEthType(Ethernet.TYPE_IPV4) | 592 | sIncomingBuilder.matchEthType(Ethernet.TYPE_IPV4) |
550 | - .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), PREFIX_LENGTH)); | 593 | + .matchIPDst(IpPrefix.valueOf(floatingIp.floatingIpAddress(), PREFIX_LENGTH)); |
551 | 594 | ||
552 | getGatewayNodeList().forEach(device -> { | 595 | getGatewayNodeList().forEach(device -> { |
553 | removeRule(device.id(), sOutgoingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); | 596 | removeRule(device.id(), sOutgoingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); |
... | @@ -580,8 +623,9 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -580,8 +623,9 @@ public class OpenstackRoutingRulePopulator { |
580 | populateL3RulestoSameNode(vmIp, openstackPort, port, device, vni); | 623 | populateL3RulestoSameNode(vmIp, openstackPort, port, device, vni); |
581 | 624 | ||
582 | deviceService.getAvailableDevices().forEach(d -> { | 625 | deviceService.getAvailableDevices().forEach(d -> { |
583 | - if (!d.equals(device) && !checkGatewayNode(d.id())) { | 626 | + if (!d.equals(device) && !d.equals(getGatewayNode())) { |
584 | - populateL3RulestoDifferentNode(vmIp, vni, d.id(), getHostIpfromOpenstackPort(openstackPort)); | 627 | + populateL3RulestoDifferentNode(vmIp, vni, d.id(), |
628 | + getHostIpfromOpenstackPort(openstackPort).getIp4Address()); | ||
585 | } | 629 | } |
586 | }); | 630 | }); |
587 | 631 | ||
... | @@ -654,7 +698,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -654,7 +698,7 @@ public class OpenstackRoutingRulePopulator { |
654 | OpenstackRoutingService routingService = getService(OpenstackRoutingService.class); | 698 | OpenstackRoutingService routingService = getService(OpenstackRoutingService.class); |
655 | 699 | ||
656 | deviceService.getAvailableDevices().forEach(d -> { | 700 | deviceService.getAvailableDevices().forEach(d -> { |
657 | - if (!checkGatewayNode(d.id())) { | 701 | + if (isTypeOf(d.id(), OpenstackNodeService.NodeType.COMPUTE)) { |
658 | routerInterfaces.forEach(routerInterface -> { | 702 | routerInterfaces.forEach(routerInterface -> { |
659 | String networkId = routingService.networkIdForRouterInterface(routerInterface.portId()); | 703 | String networkId = routingService.networkIdForRouterInterface(routerInterface.portId()); |
660 | long vni = getVni(networkId); | 704 | long vni = getVni(networkId); | ... | ... |
... | @@ -26,6 +26,7 @@ import org.onosproject.net.Host; | ... | @@ -26,6 +26,7 @@ import org.onosproject.net.Host; |
26 | import org.onosproject.net.host.HostEvent; | 26 | import org.onosproject.net.host.HostEvent; |
27 | import org.onosproject.net.host.HostListener; | 27 | import org.onosproject.net.host.HostListener; |
28 | import org.onosproject.net.host.HostService; | 28 | import org.onosproject.net.host.HostService; |
29 | +import org.onosproject.openstacknetworking.Constants; | ||
29 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
30 | 31 | ||
31 | import java.util.Objects; | 32 | import java.util.Objects; |
... | @@ -36,7 +37,7 @@ import java.util.stream.Collectors; | ... | @@ -36,7 +37,7 @@ import java.util.stream.Collectors; |
36 | 37 | ||
37 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | 38 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
38 | import static org.onlab.util.Tools.groupedThreads; | 39 | import static org.onlab.util.Tools.groupedThreads; |
39 | -import static org.onosproject.openstacknetworking.switching.Constants.*; | 40 | +import static org.onosproject.openstacknetworking.Constants.*; |
40 | import static org.slf4j.LoggerFactory.getLogger; | 41 | import static org.slf4j.LoggerFactory.getLogger; |
41 | 42 | ||
42 | /** | 43 | /** | ... | ... |
... | @@ -48,7 +48,7 @@ import java.util.Dictionary; | ... | @@ -48,7 +48,7 @@ import java.util.Dictionary; |
48 | import java.util.Set; | 48 | import java.util.Set; |
49 | 49 | ||
50 | import static com.google.common.base.Preconditions.checkNotNull; | 50 | import static com.google.common.base.Preconditions.checkNotNull; |
51 | -import static org.onosproject.openstacknetworking.switching.Constants.*; | 51 | +import static org.onosproject.openstacknetworking.Constants.*; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Handles ARP packet from VMs. | 54 | * Handles ARP packet from VMs. | ... | ... |
... | @@ -50,7 +50,7 @@ import java.util.Optional; | ... | @@ -50,7 +50,7 @@ import java.util.Optional; |
50 | import java.util.Set; | 50 | import java.util.Set; |
51 | import java.util.stream.Collectors; | 51 | import java.util.stream.Collectors; |
52 | 52 | ||
53 | -import static org.onosproject.openstacknetworking.switching.Constants.*; | 53 | +import static org.onosproject.openstacknetworking.Constants.*; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Populates flows rules for Security Groups of VMs. | 56 | * Populates flows rules for Security Groups of VMs. | ... | ... |
... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
16 | package org.onosproject.openstacknetworking.switching; | 16 | package org.onosproject.openstacknetworking.switching; |
17 | 17 | ||
18 | import com.google.common.base.Strings; | 18 | import com.google.common.base.Strings; |
19 | -import com.google.common.collect.Maps; | ||
20 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
21 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
... | @@ -27,7 +26,6 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -27,7 +26,6 @@ import org.apache.felix.scr.annotations.Service; |
27 | import org.onlab.packet.Ip4Address; | 26 | import org.onlab.packet.Ip4Address; |
28 | import org.onlab.packet.IpPrefix; | 27 | import org.onlab.packet.IpPrefix; |
29 | import org.onlab.packet.VlanId; | 28 | import org.onlab.packet.VlanId; |
30 | -import org.onlab.util.Tools; | ||
31 | import org.onosproject.core.CoreService; | 29 | import org.onosproject.core.CoreService; |
32 | import org.onosproject.dhcp.DhcpService; | 30 | import org.onosproject.dhcp.DhcpService; |
33 | import org.onosproject.dhcp.IpAssignment; | 31 | import org.onosproject.dhcp.IpAssignment; |
... | @@ -54,8 +52,6 @@ import org.onosproject.openstackinterface.OpenstackInterfaceService; | ... | @@ -54,8 +52,6 @@ import org.onosproject.openstackinterface.OpenstackInterfaceService; |
54 | import org.onosproject.openstackinterface.OpenstackNetwork; | 52 | import org.onosproject.openstackinterface.OpenstackNetwork; |
55 | import org.onosproject.openstackinterface.OpenstackPort; | 53 | import org.onosproject.openstackinterface.OpenstackPort; |
56 | import org.onosproject.openstackinterface.OpenstackSubnet; | 54 | import org.onosproject.openstackinterface.OpenstackSubnet; |
57 | -import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
58 | -import org.onosproject.openstacknetworking.OpenstackSwitchingService; | ||
59 | import org.onosproject.openstacknode.OpenstackNode; | 55 | import org.onosproject.openstacknode.OpenstackNode; |
60 | import org.onosproject.openstacknode.OpenstackNodeEvent; | 56 | import org.onosproject.openstacknode.OpenstackNodeEvent; |
61 | import org.onosproject.openstacknode.OpenstackNodeListener; | 57 | import org.onosproject.openstacknode.OpenstackNodeListener; |
... | @@ -64,7 +60,6 @@ import org.slf4j.Logger; | ... | @@ -64,7 +60,6 @@ import org.slf4j.Logger; |
64 | import org.slf4j.LoggerFactory; | 60 | import org.slf4j.LoggerFactory; |
65 | 61 | ||
66 | import java.util.Date; | 62 | import java.util.Date; |
67 | -import java.util.Map; | ||
68 | import java.util.concurrent.ExecutorService; | 63 | import java.util.concurrent.ExecutorService; |
69 | import java.util.concurrent.Executors; | 64 | import java.util.concurrent.Executors; |
70 | 65 | ||
... | @@ -74,7 +69,7 @@ import static org.onosproject.dhcp.IpAssignment.AssignmentStatus.Option_RangeNot | ... | @@ -74,7 +69,7 @@ import static org.onosproject.dhcp.IpAssignment.AssignmentStatus.Option_RangeNot |
74 | import static com.google.common.base.Preconditions.checkArgument; | 69 | import static com.google.common.base.Preconditions.checkArgument; |
75 | import static com.google.common.base.Preconditions.checkNotNull; | 70 | import static com.google.common.base.Preconditions.checkNotNull; |
76 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; | 71 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
77 | -import static org.onosproject.openstacknetworking.switching.Constants.*; | 72 | +import static org.onosproject.openstacknetworking.Constants.*; |
78 | 73 | ||
79 | @Service | 74 | @Service |
80 | @Component(immediate = true) | 75 | @Component(immediate = true) |
... | @@ -82,7 +77,7 @@ import static org.onosproject.openstacknetworking.switching.Constants.*; | ... | @@ -82,7 +77,7 @@ import static org.onosproject.openstacknetworking.switching.Constants.*; |
82 | * Populates forwarding rules for VMs created by Openstack. | 77 | * Populates forwarding rules for VMs created by Openstack. |
83 | */ | 78 | */ |
84 | public final class OpenstackSwitchingManager extends AbstractProvider | 79 | public final class OpenstackSwitchingManager extends AbstractProvider |
85 | - implements OpenstackSwitchingService, HostProvider { | 80 | + implements HostProvider { |
86 | 81 | ||
87 | private final Logger log = LoggerFactory.getLogger(getClass()); | 82 | private final Logger log = LoggerFactory.getLogger(getClass()); |
88 | 83 | ||
... | @@ -153,41 +148,6 @@ public final class OpenstackSwitchingManager extends AbstractProvider | ... | @@ -153,41 +148,6 @@ public final class OpenstackSwitchingManager extends AbstractProvider |
153 | // no probe is required | 148 | // no probe is required |
154 | } | 149 | } |
155 | 150 | ||
156 | - @Override | ||
157 | - // TODO remove this and openstackPortInfo | ||
158 | - public Map<String, OpenstackPortInfo> openstackPortInfo() { | ||
159 | - Map<String, OpenstackPortInfo> portInfoMap = Maps.newHashMap(); | ||
160 | - | ||
161 | - Tools.stream(hostService.getHosts()).filter(this::isValidHost).forEach(host -> { | ||
162 | - Port port = deviceService.getPort( | ||
163 | - host.location().deviceId(), | ||
164 | - host.location().port()); | ||
165 | - | ||
166 | - OpenstackPortInfo portInfo = OpenstackPortInfo.builder() | ||
167 | - .setDeviceId(host.location().deviceId()) | ||
168 | - .setHostMac(host.mac()) | ||
169 | - .setNetworkId(host.annotations().value(NETWORK_ID)) | ||
170 | - .setGatewayIP(Ip4Address.valueOf(host.annotations().value(GATEWAY_IP))) | ||
171 | - .setVni(Long.valueOf(host.annotations().value(VXLAN_ID))) | ||
172 | - .setHostIp(host.ipAddresses().stream().findFirst().get().getIp4Address()) | ||
173 | - .build(); | ||
174 | - | ||
175 | - portInfoMap.put(port.annotations().value(PORT_NAME), portInfo); | ||
176 | - }); | ||
177 | - | ||
178 | - return portInfoMap; | ||
179 | - } | ||
180 | - | ||
181 | - // TODO remove this and openstackPortInfo | ||
182 | - private boolean isValidHost(Host host) { | ||
183 | - return !host.ipAddresses().isEmpty() && | ||
184 | - host.annotations().value(VXLAN_ID) != null && | ||
185 | - host.annotations().value(NETWORK_ID) != null && | ||
186 | - host.annotations().value(TENANT_ID) != null && | ||
187 | - host.annotations().value(GATEWAY_IP) != null && | ||
188 | - host.annotations().value(PORT_ID) != null; | ||
189 | - } | ||
190 | - | ||
191 | private void processPortAdded(Port port) { | 151 | private void processPortAdded(Port port) { |
192 | // TODO check the node state is COMPLETE | 152 | // TODO check the node state is COMPLETE |
193 | OpenstackPort osPort = openstackService.port(port); | 153 | OpenstackPort osPort = openstackService.port(port); | ... | ... |
... | @@ -47,7 +47,7 @@ import java.util.Objects; | ... | @@ -47,7 +47,7 @@ import java.util.Objects; |
47 | import java.util.Optional; | 47 | import java.util.Optional; |
48 | 48 | ||
49 | import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST; | 49 | import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST; |
50 | -import static org.onosproject.openstacknetworking.switching.Constants.*; | 50 | +import static org.onosproject.openstacknetworking.Constants.*; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Populates switching flow rules. | 53 | * Populates switching flow rules. | ... | ... |
... | @@ -50,6 +50,7 @@ import org.onosproject.scalablegateway.api.GatewayNodeConfig; | ... | @@ -50,6 +50,7 @@ import org.onosproject.scalablegateway.api.GatewayNodeConfig; |
50 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 50 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
51 | 51 | ||
52 | import java.util.List; | 52 | import java.util.List; |
53 | +import java.util.Optional; | ||
53 | 54 | ||
54 | import org.onosproject.store.serializers.KryoNamespaces; | 55 | import org.onosproject.store.serializers.KryoNamespaces; |
55 | import org.onosproject.store.service.ConsistentMap; | 56 | import org.onosproject.store.service.ConsistentMap; |
... | @@ -128,7 +129,6 @@ public class ScalableGatewayManager implements ScalableGatewayService { | ... | @@ -128,7 +129,6 @@ public class ScalableGatewayManager implements ScalableGatewayService { |
128 | deviceService.addListener(internalDeviceListener); | 129 | deviceService.addListener(internalDeviceListener); |
129 | 130 | ||
130 | selectGroupHandler = new SelectGroupHandler(groupService, deviceService, driverService, appId); | 131 | selectGroupHandler = new SelectGroupHandler(groupService, deviceService, driverService, appId); |
131 | - readConfiguration(); | ||
132 | 132 | ||
133 | gatewayNodeMap = storageService.<DeviceId, GatewayNode>consistentMapBuilder() | 133 | gatewayNodeMap = storageService.<DeviceId, GatewayNode>consistentMapBuilder() |
134 | .withSerializer(Serializer.using(GATEWAYNODE_SERIALIZER.build())) | 134 | .withSerializer(Serializer.using(GATEWAYNODE_SERIALIZER.build())) |
... | @@ -165,13 +165,17 @@ public class ScalableGatewayManager implements ScalableGatewayService { | ... | @@ -165,13 +165,17 @@ public class ScalableGatewayManager implements ScalableGatewayService { |
165 | } | 165 | } |
166 | 166 | ||
167 | private PortNumber findPortNumFromPortName(DeviceId gatewayDeviceId, String name) { | 167 | private PortNumber findPortNumFromPortName(DeviceId gatewayDeviceId, String name) { |
168 | - Port port = deviceService.getPorts(gatewayDeviceId) | 168 | + Optional<Port> port = deviceService.getPorts(gatewayDeviceId) |
169 | .stream() | 169 | .stream() |
170 | .filter(p -> p.annotations().value(PORT_NAME).equals(name)) | 170 | .filter(p -> p.annotations().value(PORT_NAME).equals(name)) |
171 | - .iterator() | 171 | + .findFirst(); |
172 | - .next(); | ||
173 | - return checkNotNull(port, PORT_CAN_NOT_BE_NULL).number(); | ||
174 | 172 | ||
173 | + if (!port.isPresent()) { | ||
174 | + log.error("Cannot find port {} in gateway device {}", name, gatewayDeviceId); | ||
175 | + return null; | ||
176 | + } | ||
177 | + | ||
178 | + return port.get().number(); | ||
175 | } | 179 | } |
176 | 180 | ||
177 | @Override | 181 | @Override | ... | ... |
-
Please register or login to post a comment