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