Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 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.openstacknode.impl; |
| 17 | |
| 18 | import com.google.common.base.Strings; |
| 19 | import com.google.common.collect.ImmutableSet; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 20 | import org.onlab.util.Tools; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 21 | import org.onosproject.cluster.ClusterService; |
| 22 | import org.onosproject.cluster.LeadershipService; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.CoreService; |
| 25 | import org.onosproject.event.ListenerRegistry; |
| 26 | import org.onosproject.net.DeviceId; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 27 | import org.onosproject.net.device.DeviceService; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 28 | import org.onosproject.openstacknode.api.OpenstackNode; |
| 29 | import org.onosproject.openstacknode.api.OpenstackNodeAdminService; |
| 30 | import org.onosproject.openstacknode.api.OpenstackNodeEvent; |
| 31 | import org.onosproject.openstacknode.api.OpenstackNodeListener; |
| 32 | import org.onosproject.openstacknode.api.OpenstackNodeService; |
| 33 | import org.onosproject.openstacknode.api.OpenstackNodeStore; |
| 34 | import org.onosproject.openstacknode.api.OpenstackNodeStoreDelegate; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 35 | import org.onosproject.ovsdb.controller.OvsdbController; |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 36 | import org.onosproject.store.service.AtomicCounter; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 37 | import org.onosproject.store.service.StorageService; |
| 38 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 39 | import org.osgi.service.component.annotations.Activate; |
| 40 | import org.osgi.service.component.annotations.Component; |
| 41 | import org.osgi.service.component.annotations.Deactivate; |
| 42 | import org.osgi.service.component.annotations.Modified; |
| 43 | import org.osgi.service.component.annotations.Reference; |
| 44 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 45 | import org.slf4j.Logger; |
| 46 | |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 47 | import java.util.Dictionary; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 48 | import java.util.Objects; |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 49 | import java.util.Optional; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 50 | import java.util.Set; |
| 51 | import java.util.concurrent.ExecutorService; |
Daniel Park | 5a6a710 | 2018-09-06 23:58:33 +0900 | [diff] [blame] | 52 | import java.util.concurrent.TimeUnit; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 53 | import java.util.stream.Collectors; |
| 54 | |
| 55 | import static com.google.common.base.Preconditions.checkArgument; |
| 56 | import static com.google.common.base.Preconditions.checkNotNull; |
| 57 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 58 | import static org.onlab.packet.TpPort.tpPort; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 59 | import static org.onlab.util.Tools.groupedThreads; |
Daniel Park | 5a6a710 | 2018-09-06 23:58:33 +0900 | [diff] [blame] | 60 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 61 | import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 62 | import static org.onosproject.openstacknode.api.NodeState.COMPLETE; |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 63 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER; |
Daniel Park | 5a6a710 | 2018-09-06 23:58:33 +0900 | [diff] [blame] | 64 | import static org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveSystemInterface; |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 65 | import static org.onosproject.openstacknode.util.OpenstackNodeUtil.genDpid; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 66 | import static org.onosproject.openstacknode.util.OpenstackNodeUtil.isOvsdbConnected; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 67 | import static org.slf4j.LoggerFactory.getLogger; |
| 68 | |
| 69 | /** |
| 70 | * Service administering the inventory of openstack nodes. |
| 71 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 72 | @Component(immediate = true, service = { OpenstackNodeService.class, OpenstackNodeAdminService.class }) |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 73 | public class OpenstackNodeManager extends ListenerRegistry<OpenstackNodeEvent, OpenstackNodeListener> |
| 74 | implements OpenstackNodeService, OpenstackNodeAdminService { |
| 75 | |
Jian Li | 5afbea4 | 2018-02-28 10:37:03 +0900 | [diff] [blame] | 76 | private final Logger log = getLogger(getClass()); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 77 | |
| 78 | private static final String MSG_NODE = "OpenStack node %s %s"; |
| 79 | private static final String MSG_CREATED = "created"; |
| 80 | private static final String MSG_UPDATED = "updated"; |
| 81 | private static final String MSG_REMOVED = "removed"; |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 82 | private static final String OVSDB_PORT = "ovsdbPortNum"; |
| 83 | private static final int DEFAULT_OVSDB_PORT = 6640; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 84 | |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 85 | private static final String DEVICE_ID_COUNTER_NAME = "device-id-counter"; |
| 86 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 87 | private static final String ERR_NULL_NODE = "OpenStack node cannot be null"; |
| 88 | private static final String ERR_NULL_HOSTNAME = "OpenStack node hostname cannot be null"; |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 89 | private static final String ERR_NULL_DEVICE_ID = "OpenStack node device ID cannot be null"; |
| 90 | |
| 91 | private static final String NOT_DUPLICATED_MSG = "% cannot be duplicated"; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 92 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 93 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 94 | protected OpenstackNodeStore osNodeStore; |
| 95 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 96 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 97 | protected CoreService coreService; |
| 98 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 99 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 100 | protected ClusterService clusterService; |
| 101 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 102 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 103 | protected LeadershipService leadershipService; |
| 104 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 106 | protected StorageService storageService; |
| 107 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 108 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 109 | protected OvsdbController ovsdbController; |
| 110 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 112 | protected DeviceService deviceService; |
| 113 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 114 | //@Property(name = OVSDB_PORT, intValue = DEFAULT_OVSDB_PORT, |
| 115 | // label = "OVSDB server listen port") |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 116 | private int ovsdbPort = DEFAULT_OVSDB_PORT; |
| 117 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 118 | private final ExecutorService eventExecutor = newSingleThreadExecutor( |
| 119 | groupedThreads(this.getClass().getSimpleName(), "event-handler", log)); |
| 120 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 121 | private final OpenstackNodeStoreDelegate delegate = new InternalNodeStoreDelegate(); |
| 122 | |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 123 | private AtomicCounter deviceIdCounter; |
| 124 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 125 | private ApplicationId appId; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 126 | |
| 127 | @Activate |
| 128 | protected void activate() { |
| 129 | appId = coreService.registerApplication(APP_ID); |
| 130 | osNodeStore.setDelegate(delegate); |
| 131 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 132 | leadershipService.runForLeadership(appId.name()); |
| 133 | |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 134 | deviceIdCounter = storageService.getAtomicCounter(DEVICE_ID_COUNTER_NAME); |
| 135 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 136 | log.info("Started"); |
| 137 | } |
| 138 | |
| 139 | @Deactivate |
| 140 | protected void deactivate() { |
| 141 | osNodeStore.unsetDelegate(delegate); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 142 | |
| 143 | leadershipService.withdraw(appId.name()); |
| 144 | eventExecutor.shutdown(); |
| 145 | |
| 146 | log.info("Stopped"); |
| 147 | } |
| 148 | |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 149 | @Modified |
| 150 | protected void modified(ComponentContext context) { |
| 151 | Dictionary<?, ?> properties = context.getProperties(); |
| 152 | int updatedOvsdbPort = Tools.getIntegerProperty(properties, OVSDB_PORT); |
| 153 | if (!Objects.equals(updatedOvsdbPort, ovsdbPort)) { |
| 154 | ovsdbPort = updatedOvsdbPort; |
| 155 | } |
| 156 | |
| 157 | log.info("Modified"); |
| 158 | } |
| 159 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 160 | @Override |
| 161 | public void createNode(OpenstackNode osNode) { |
| 162 | checkNotNull(osNode, ERR_NULL_NODE); |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 163 | |
| 164 | OpenstackNode updatedNode; |
| 165 | |
| 166 | if (osNode.intgBridge() == null && osNode.type() != CONTROLLER) { |
| 167 | String deviceIdStr = genDpid(deviceIdCounter.incrementAndGet()); |
| 168 | checkNotNull(deviceIdStr, ERR_NULL_DEVICE_ID); |
| 169 | updatedNode = osNode.updateIntbridge(DeviceId.deviceId(deviceIdStr)); |
| 170 | checkArgument(!hasIntgBridge(updatedNode.intgBridge(), updatedNode.hostname()), |
| 171 | NOT_DUPLICATED_MSG, updatedNode.intgBridge()); |
| 172 | } else { |
| 173 | updatedNode = osNode; |
| 174 | checkArgument(!hasIntgBridge(updatedNode.intgBridge(), updatedNode.hostname()), |
| 175 | NOT_DUPLICATED_MSG, updatedNode.intgBridge()); |
| 176 | } |
| 177 | |
| 178 | osNodeStore.createNode(updatedNode); |
| 179 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 180 | log.info(String.format(MSG_NODE, osNode.hostname(), MSG_CREATED)); |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void updateNode(OpenstackNode osNode) { |
| 185 | checkNotNull(osNode, ERR_NULL_NODE); |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 186 | |
| 187 | OpenstackNode updatedNode; |
| 188 | |
Daniel Park | 5a6a710 | 2018-09-06 23:58:33 +0900 | [diff] [blame] | 189 | OpenstackNode existingNode = osNodeStore.node(osNode.hostname()); |
| 190 | checkNotNull(existingNode, ERR_NULL_NODE); |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 191 | |
| 192 | DeviceId existDeviceId = osNodeStore.node(osNode.hostname()).intgBridge(); |
| 193 | |
Daniel Park | 5a6a710 | 2018-09-06 23:58:33 +0900 | [diff] [blame] | 194 | if (vlanIntfChanged(existingNode, osNode) || |
| 195 | physicalIntfChanged(existingNode, osNode) || |
| 196 | dpdkIntfChanged(existingNode, osNode)) { |
| 197 | |
| 198 | removeNode(osNode.hostname()); |
| 199 | |
| 200 | //we wait 1 second for ovsdb client completely to do removal job |
| 201 | try { |
| 202 | TimeUnit.MILLISECONDS.sleep(1000); |
| 203 | } catch (InterruptedException e) { |
| 204 | log.error("Exception occurred because of {}", e); |
| 205 | } |
| 206 | |
| 207 | if (!intfsRemovedFromExistNode(existingNode)) { |
| 208 | log.error("Updated node failed because intfs of existingNode {} are not removed properly", |
| 209 | existingNode.toString()); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | createNode(osNode); |
| 214 | return; |
| 215 | } |
| 216 | |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 217 | if (osNode.intgBridge() == null && osNode.type() != CONTROLLER) { |
| 218 | updatedNode = osNode.updateIntbridge(existDeviceId); |
| 219 | checkArgument(!hasIntgBridge(updatedNode.intgBridge(), updatedNode.hostname()), |
| 220 | NOT_DUPLICATED_MSG, updatedNode.intgBridge()); |
| 221 | } else { |
| 222 | updatedNode = osNode; |
| 223 | checkArgument(!hasIntgBridge(updatedNode.intgBridge(), updatedNode.hostname()), |
| 224 | NOT_DUPLICATED_MSG, updatedNode.intgBridge()); |
| 225 | } |
| 226 | |
| 227 | osNodeStore.updateNode(updatedNode); |
| 228 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 229 | log.info(String.format(MSG_NODE, osNode.hostname(), MSG_UPDATED)); |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public OpenstackNode removeNode(String hostname) { |
| 234 | checkArgument(!Strings.isNullOrEmpty(hostname), ERR_NULL_HOSTNAME); |
| 235 | OpenstackNode osNode = osNodeStore.removeNode(hostname); |
| 236 | log.info(String.format(MSG_NODE, hostname, MSG_REMOVED)); |
| 237 | return osNode; |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public Set<OpenstackNode> nodes() { |
| 242 | return osNodeStore.nodes(); |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public Set<OpenstackNode> nodes(OpenstackNode.NodeType type) { |
| 247 | Set<OpenstackNode> osNodes = osNodeStore.nodes().stream() |
| 248 | .filter(osNode -> Objects.equals(osNode.type(), type)) |
| 249 | .collect(Collectors.toSet()); |
| 250 | return ImmutableSet.copyOf(osNodes); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public Set<OpenstackNode> completeNodes() { |
| 255 | Set<OpenstackNode> osNodes = osNodeStore.nodes().stream() |
| 256 | .filter(osNode -> Objects.equals(osNode.state(), COMPLETE)) |
| 257 | .collect(Collectors.toSet()); |
| 258 | return ImmutableSet.copyOf(osNodes); |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public Set<OpenstackNode> completeNodes(OpenstackNode.NodeType type) { |
| 263 | Set<OpenstackNode> osNodes = osNodeStore.nodes().stream() |
| 264 | .filter(osNode -> osNode.type() == type && |
| 265 | Objects.equals(osNode.state(), COMPLETE)) |
| 266 | .collect(Collectors.toSet()); |
| 267 | return ImmutableSet.copyOf(osNodes); |
| 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public OpenstackNode node(String hostname) { |
| 272 | return osNodeStore.node(hostname); |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public OpenstackNode node(DeviceId deviceId) { |
Jian Li | 5afbea4 | 2018-02-28 10:37:03 +0900 | [diff] [blame] | 277 | return osNodeStore.nodes().stream() |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 278 | .filter(osNode -> Objects.equals(osNode.intgBridge(), deviceId) || |
daniel park | b18424c | 2018-02-05 15:43:43 +0900 | [diff] [blame] | 279 | Objects.equals(osNode.ovsdb(), deviceId)) |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 280 | .findFirst().orElse(null); |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 281 | } |
| 282 | |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 283 | @Override |
| 284 | public void addVfPort(OpenstackNode osNode, String portName) { |
| 285 | log.trace("addVfPort called"); |
| 286 | |
Jian Li | b787342 | 2018-08-18 22:34:39 +0900 | [diff] [blame] | 287 | connectSwitch(osNode); |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 288 | |
Daniel Park | 5a6a710 | 2018-09-06 23:58:33 +0900 | [diff] [blame] | 289 | addOrRemoveSystemInterface(osNode, INTEGRATION_BRIDGE, portName, deviceService, true); |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void removeVfPort(OpenstackNode osNode, String portName) { |
| 294 | log.trace("removeVfPort called"); |
| 295 | |
Jian Li | b787342 | 2018-08-18 22:34:39 +0900 | [diff] [blame] | 296 | connectSwitch(osNode); |
| 297 | |
Daniel Park | 5a6a710 | 2018-09-06 23:58:33 +0900 | [diff] [blame] | 298 | addOrRemoveSystemInterface(osNode, INTEGRATION_BRIDGE, portName, deviceService, false); |
| 299 | } |
| 300 | |
| 301 | private boolean intfsRemovedFromExistNode(OpenstackNode osNode) { |
| 302 | if (osNode.vlanIntf() != null && |
| 303 | !intfRemoved(osNode.vlanIntf(), osNode.intgBridge())) { |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | if (osNode.phyIntfs().stream().anyMatch(phyInterface -> |
| 308 | !intfRemoved(phyInterface.intf(), osNode.intgBridge()))) { |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | if (osNode.dpdkConfig() != null && |
| 313 | osNode.dpdkConfig().dpdkIntfs().stream().anyMatch(dpdkInterface -> |
| 314 | !intfRemoved(dpdkInterface.intf(), osNode.intgBridge()))) { |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | private boolean intfRemoved(String intf, DeviceId deviceId) { |
| 322 | return !deviceService.getPorts(deviceId).stream() |
| 323 | .anyMatch(port -> port.annotations().value(PORT_NAME).equals(intf)); |
| 324 | } |
| 325 | |
| 326 | private boolean vlanIntfChanged(OpenstackNode oldNode, OpenstackNode newNode) { |
| 327 | return !Objects.equals(oldNode.vlanIntf(), newNode.vlanIntf()); |
| 328 | } |
| 329 | |
| 330 | private boolean physicalIntfChanged(OpenstackNode oldNode, OpenstackNode newNode) { |
| 331 | return !Objects.equals(oldNode.phyIntfs(), newNode.phyIntfs()); |
| 332 | } |
| 333 | |
| 334 | private boolean dpdkIntfChanged(OpenstackNode oldNode, OpenstackNode newNode) { |
| 335 | return !Objects.equals(oldNode.dpdkConfig(), newNode.dpdkConfig()); |
Jian Li | b787342 | 2018-08-18 22:34:39 +0900 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | private void connectSwitch(OpenstackNode osNode) { |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 339 | if (!isOvsdbConnected(osNode, ovsdbPort, ovsdbController, deviceService)) { |
| 340 | log.warn("There's no ovsdb connection with the device {}. Try to connect the device...", |
| 341 | osNode.ovsdb().toString()); |
| 342 | try { |
| 343 | ovsdbController.connect(osNode.managementIp(), tpPort(ovsdbPort)); |
| 344 | } catch (Exception e) { |
| 345 | log.error("Failed to connect to the openstackNode via ovsdb protocol because of exception {}", |
| 346 | e.toString()); |
| 347 | } |
| 348 | } |
Daniel Park | c4d0640 | 2018-05-28 15:57:37 +0900 | [diff] [blame] | 349 | } |
| 350 | |
Jian Li | e314154 | 2018-08-13 18:05:43 +0900 | [diff] [blame] | 351 | private boolean hasIntgBridge(DeviceId deviceId, String hostname) { |
| 352 | Optional<OpenstackNode> existNode = osNodeStore.nodes().stream() |
| 353 | .filter(n -> n.type() != CONTROLLER) |
| 354 | .filter(n -> !n.hostname().equals(hostname)) |
| 355 | .filter(n -> n.intgBridge().equals(deviceId)) |
| 356 | .findFirst(); |
| 357 | |
| 358 | return existNode.isPresent(); |
| 359 | } |
| 360 | |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 361 | private class InternalNodeStoreDelegate implements OpenstackNodeStoreDelegate { |
| 362 | |
| 363 | @Override |
| 364 | public void notify(OpenstackNodeEvent event) { |
| 365 | if (event != null) { |
| 366 | log.trace("send openstack node event {}", event); |
| 367 | process(event); |
| 368 | } |
| 369 | } |
| 370 | } |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 371 | } |