Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8e57fd5 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [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 | */ |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 16 | package org.opencord.cordvtn.impl; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 17 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 18 | import com.google.common.base.Strings; |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 19 | import com.jcraft.jsch.Session; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 26 | import org.onlab.packet.IpAddress; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 27 | import org.onlab.util.KryoNamespace; |
| 28 | import org.onosproject.cluster.ClusterService; |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 29 | import org.onosproject.cluster.LeadershipService; |
| 30 | import org.onosproject.cluster.NodeId; |
Hyunsun Moon | c031d9b | 2016-08-04 13:57:22 -0700 | [diff] [blame] | 31 | import org.onosproject.net.AnnotationKeys; |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 32 | import org.onosproject.net.behaviour.BridgeDescription; |
| 33 | import org.onosproject.net.behaviour.DefaultBridgeDescription; |
| 34 | import org.onosproject.net.behaviour.InterfaceConfig; |
| 35 | import org.onosproject.net.behaviour.TunnelEndPoints; |
| 36 | import org.onosproject.net.behaviour.TunnelKeys; |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 37 | import org.onosproject.net.config.ConfigFactory; |
| 38 | import org.onosproject.net.config.basics.SubjectFactories; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 39 | import org.opencord.cordvtn.api.ConnectionHandler; |
| 40 | import org.opencord.cordvtn.api.CordVtnConfig; |
| 41 | import org.opencord.cordvtn.api.CordVtnNode; |
| 42 | import org.opencord.cordvtn.api.CordVtnNodeState; |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 43 | import org.opencord.cordvtn.api.InstanceService; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 44 | import org.opencord.cordvtn.api.NetworkAddress; |
| 45 | import org.opencord.cordvtn.api.SshAccessInfo; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 46 | import org.onosproject.core.ApplicationId; |
| 47 | import org.onosproject.core.CoreService; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 48 | import org.onosproject.net.ConnectPoint; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 49 | import org.onosproject.net.Device; |
| 50 | import org.onosproject.net.DeviceId; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 51 | import org.onosproject.net.Port; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 52 | import org.onosproject.net.PortNumber; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 53 | import org.onosproject.net.behaviour.BridgeConfig; |
| 54 | import org.onosproject.net.behaviour.BridgeName; |
| 55 | import org.onosproject.net.behaviour.ControllerInfo; |
| 56 | import org.onosproject.net.behaviour.DefaultTunnelDescription; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 57 | import org.onosproject.net.behaviour.TunnelDescription; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 58 | import org.onosproject.net.config.NetworkConfigEvent; |
| 59 | import org.onosproject.net.config.NetworkConfigListener; |
| 60 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 61 | import org.onosproject.net.config.NetworkConfigService; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 62 | import org.onosproject.net.device.DeviceAdminService; |
| 63 | import org.onosproject.net.device.DeviceEvent; |
| 64 | import org.onosproject.net.device.DeviceListener; |
| 65 | import org.onosproject.net.device.DeviceService; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 66 | import org.onosproject.net.host.HostService; |
| 67 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
| 68 | import org.onosproject.ovsdb.controller.OvsdbController; |
| 69 | import org.onosproject.ovsdb.controller.OvsdbNodeId; |
| 70 | import org.onosproject.store.serializers.KryoNamespaces; |
| 71 | import org.onosproject.store.service.ConsistentMap; |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 72 | import org.onosproject.store.service.MapEvent; |
| 73 | import org.onosproject.store.service.MapEventListener; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 74 | import org.onosproject.store.service.Serializer; |
| 75 | import org.onosproject.store.service.StorageService; |
Hyunsun Moon | d05b32e | 2016-03-02 19:27:26 -0800 | [diff] [blame] | 76 | import org.onosproject.store.service.Versioned; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 77 | import org.slf4j.Logger; |
| 78 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 79 | import java.util.List; |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 80 | import java.util.Objects; |
Hyunsun Moon | c031d9b | 2016-08-04 13:57:22 -0700 | [diff] [blame] | 81 | import java.util.Optional; |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 82 | import java.util.Set; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 83 | import java.util.concurrent.ExecutorService; |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 84 | import java.util.stream.Collectors; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 85 | |
| 86 | import static com.google.common.base.Preconditions.checkNotNull; |
Hyunsun Moon | 537018f | 2016-07-27 18:51:00 -0700 | [diff] [blame] | 87 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 88 | import static org.onlab.util.Tools.groupedThreads; |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 89 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 90 | import static org.onosproject.net.Device.Type.SWITCH; |
| 91 | import static org.onosproject.net.behaviour.TunnelDescription.Type.VXLAN; |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 92 | import static org.opencord.cordvtn.api.Constants.*; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 93 | import static org.opencord.cordvtn.impl.RemoteIpCommandUtil.*; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 94 | import static org.slf4j.LoggerFactory.getLogger; |
| 95 | |
| 96 | /** |
| 97 | * Reads node information from the network config file and handles the config |
| 98 | * update events. |
| 99 | * Only a leader controller performs the node addition or deletion. |
| 100 | */ |
| 101 | @Component(immediate = true) |
| 102 | @Service(value = CordVtnNodeManager.class) |
| 103 | public class CordVtnNodeManager { |
| 104 | |
| 105 | protected final Logger log = getLogger(getClass()); |
| 106 | |
| 107 | private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder() |
| 108 | .register(KryoNamespaces.API) |
| 109 | .register(CordVtnNode.class) |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 110 | .register(NodeState.class) |
| 111 | .register(SshAccessInfo.class) |
| 112 | .register(NetworkAddress.class); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 113 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 114 | private static final int DPID_BEGIN = 3; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 115 | |
| 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 117 | protected CoreService coreService; |
| 118 | |
| 119 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 120 | protected NetworkConfigRegistry configRegistry; |
| 121 | |
| 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 123 | protected NetworkConfigService configService; |
| 124 | |
| 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 126 | protected StorageService storageService; |
| 127 | |
| 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 129 | protected DeviceAdminService adminService; |
| 130 | |
| 131 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 132 | protected OvsdbController ovsdbController; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 133 | |
| 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 135 | protected ClusterService clusterService; |
| 136 | |
| 137 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 138 | protected DeviceService deviceService; |
| 139 | |
| 140 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 141 | protected HostService hostService; |
| 142 | |
| 143 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 144 | protected LeadershipService leadershipService; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 145 | |
| 146 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 147 | protected InstanceService instanceService; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 148 | |
| 149 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 150 | protected CordVtnPipeline pipeline; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 151 | |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 152 | private static final Class<CordVtnConfig> CONFIG_CLASS = CordVtnConfig.class; |
| 153 | private final ConfigFactory configFactory = |
| 154 | new ConfigFactory<ApplicationId, CordVtnConfig>( |
| 155 | SubjectFactories.APP_SUBJECT_FACTORY, CONFIG_CLASS, "cordvtn") { |
| 156 | @Override |
| 157 | public CordVtnConfig createConfig() { |
| 158 | return new CordVtnConfig(); |
| 159 | } |
| 160 | }; |
| 161 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 162 | private final ExecutorService eventExecutor = |
Hyunsun Moon | 537018f | 2016-07-27 18:51:00 -0700 | [diff] [blame] | 163 | newSingleThreadExecutor(groupedThreads("onos/cordvtn-node", "event-handler", log)); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 164 | |
| 165 | private final NetworkConfigListener configListener = new InternalConfigListener(); |
| 166 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 167 | private final MapEventListener<String, CordVtnNode> nodeStoreListener = new InternalMapListener(); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 168 | |
| 169 | private final OvsdbHandler ovsdbHandler = new OvsdbHandler(); |
| 170 | private final BridgeHandler bridgeHandler = new BridgeHandler(); |
| 171 | |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 172 | private ConsistentMap<String, CordVtnNode> nodeStore; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 173 | private ApplicationId appId; |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 174 | private NodeId localNodeId; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 175 | |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 176 | private enum NodeState implements CordVtnNodeState { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 177 | |
| 178 | INIT { |
| 179 | @Override |
| 180 | public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 181 | // make sure there is OVSDB connection |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 182 | if (!nodeManager.isOvsdbConnected(node)) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 183 | nodeManager.connectOvsdb(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 184 | return; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 185 | } |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 186 | nodeManager.createIntegrationBridge(node); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 187 | } |
| 188 | }, |
| 189 | BRIDGE_CREATED { |
| 190 | @Override |
| 191 | public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 192 | // make sure there is OVSDB connection |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 193 | if (!nodeManager.isOvsdbConnected(node)) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 194 | nodeManager.connectOvsdb(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
| 198 | nodeManager.createTunnelInterface(node); |
| 199 | nodeManager.addSystemInterface(node, node.dataIface()); |
| 200 | if (node.hostMgmtIface().isPresent()) { |
| 201 | nodeManager.addSystemInterface(node, node.hostMgmtIface().get()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | }, |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 205 | PORTS_ADDED { |
Hyunsun Moon | bd572c1 | 2016-01-21 00:54:52 -0800 | [diff] [blame] | 206 | @Override |
| 207 | public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 208 | nodeManager.setIpAddress(node); |
Hyunsun Moon | bd572c1 | 2016-01-21 00:54:52 -0800 | [diff] [blame] | 209 | } |
Hyunsun Moon | bd572c1 | 2016-01-21 00:54:52 -0800 | [diff] [blame] | 210 | }, |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 211 | COMPLETE { |
| 212 | @Override |
| 213 | public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { |
| 214 | nodeManager.postInit(node); |
| 215 | } |
| 216 | }, |
| 217 | INCOMPLETE { |
| 218 | @Override |
| 219 | public void process(CordVtnNodeManager nodeManager, CordVtnNode node) { |
| 220 | } |
| 221 | }; |
| 222 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 223 | public abstract void process(CordVtnNodeManager nodeManager, CordVtnNode node); |
| 224 | } |
| 225 | |
| 226 | @Activate |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 227 | protected void activate() { |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 228 | appId = coreService.registerApplication(CORDVTN_APP_ID); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 229 | |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 230 | configRegistry.registerConfigFactory(configFactory); |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 231 | localNodeId = clusterService.getLocalNode().id(); |
| 232 | leadershipService.runForLeadership(appId.name()); |
| 233 | |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 234 | nodeStore = storageService.<String, CordVtnNode>consistentMapBuilder() |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 235 | .withSerializer(Serializer.using(NODE_SERIALIZER.build())) |
| 236 | .withName("cordvtn-nodestore") |
| 237 | .withApplicationId(appId) |
| 238 | .build(); |
| 239 | |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 240 | nodeStore.addListener(nodeStoreListener); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 241 | deviceService.addListener(deviceListener); |
| 242 | configService.addListener(configListener); |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 243 | |
| 244 | log.info("Started"); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Deactivate |
| 248 | protected void deactivate() { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 249 | configService.removeListener(configListener); |
| 250 | deviceService.removeListener(deviceListener); |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 251 | nodeStore.removeListener(nodeStoreListener); |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 252 | |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 253 | leadershipService.withdraw(appId.name()); |
Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [diff] [blame] | 254 | configRegistry.unregisterConfigFactory(configFactory); |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 255 | eventExecutor.shutdown(); |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 256 | |
| 257 | log.info("Stopped"); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 261 | * Adds or updates a new node to the service. |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 262 | * |
| 263 | * @param node cordvtn node |
| 264 | */ |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 265 | public void addOrUpdateNode(CordVtnNode node) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 266 | checkNotNull(node); |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 267 | nodeStore.put(node.hostname(), CordVtnNode.getUpdatedNode(node, getNodeState(node))); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Deletes a node from the service. |
| 272 | * |
| 273 | * @param node cordvtn node |
| 274 | */ |
| 275 | public void deleteNode(CordVtnNode node) { |
| 276 | checkNotNull(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 277 | OvsdbClientService ovsdbClient = getOvsdbClient(node); |
| 278 | if (ovsdbClient != null && ovsdbClient.isConnected()) { |
| 279 | ovsdbClient.disconnect(); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 280 | } |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 281 | nodeStore.remove(node.hostname()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 285 | * Returns node initialization state. |
| 286 | * |
| 287 | * @param node cordvtn node |
| 288 | * @return true if initial node setup is completed, otherwise false |
| 289 | */ |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 290 | public boolean isNodeInitComplete(CordVtnNode node) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 291 | checkNotNull(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 292 | return getNodeState(node).equals(NodeState.COMPLETE); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Returns the number of the nodes known to the service. |
| 297 | * |
| 298 | * @return number of nodes |
| 299 | */ |
| 300 | public int getNodeCount() { |
| 301 | return nodeStore.size(); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Returns all nodes known to the service. |
| 306 | * |
| 307 | * @return list of nodes |
| 308 | */ |
| 309 | public List<CordVtnNode> getNodes() { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 310 | return nodeStore.values().stream().map(Versioned::value).collect(Collectors.toList()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /** |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 314 | * Returns all nodes in complete state. |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 315 | * |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 316 | * @return set of nodes |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 317 | */ |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 318 | public Set<CordVtnNode> completeNodes() { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 319 | return getNodes().stream().filter(this::isNodeStateComplete) |
| 320 | .collect(Collectors.toSet()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /** |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 324 | * Returns physical data plane port number of a given device. |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 325 | * |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 326 | * @param deviceId integration bridge device id |
| 327 | * @return port number; null otherwise |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 328 | */ |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 329 | public PortNumber dataPort(DeviceId deviceId) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 330 | CordVtnNode node = nodeByBridgeId(deviceId); |
| 331 | if (node == null) { |
| 332 | log.warn("Failed to get node for {}", deviceId); |
| 333 | return null; |
| 334 | } |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 335 | |
Hyunsun Moon | c031d9b | 2016-08-04 13:57:22 -0700 | [diff] [blame] | 336 | Optional<PortNumber> port = getPortNumber(deviceId, node.dataIface()); |
| 337 | return port.isPresent() ? port.get() : null; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Returns physical data plane IP address of a given device. |
| 342 | * |
| 343 | * @param deviceId integration bridge device id |
| 344 | * @return ip address; null otherwise |
| 345 | */ |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 346 | public IpAddress dataIp(DeviceId deviceId) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 347 | CordVtnNode node = nodeByBridgeId(deviceId); |
| 348 | if (node == null) { |
| 349 | log.warn("Failed to get node for {}", deviceId); |
| 350 | return null; |
| 351 | } |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 352 | return node.dataIp().ip(); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Returns tunnel port number of a given device. |
| 357 | * |
| 358 | * @param deviceId integration bridge device id |
| 359 | * @return port number |
| 360 | */ |
| 361 | public PortNumber tunnelPort(DeviceId deviceId) { |
Hyunsun Moon | c031d9b | 2016-08-04 13:57:22 -0700 | [diff] [blame] | 362 | Optional<PortNumber> port = getPortNumber(deviceId, DEFAULT_TUNNEL); |
| 363 | return port.isPresent() ? port.get() : null; |
| 364 | } |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 365 | |
Hyunsun Moon | c031d9b | 2016-08-04 13:57:22 -0700 | [diff] [blame] | 366 | /** |
| 367 | * Returns host management interface port number if exists. |
| 368 | * |
| 369 | * @param deviceId integration bridge device id |
| 370 | * @return port number; null if it does not exist |
| 371 | */ |
| 372 | public PortNumber hostManagementPort(DeviceId deviceId) { |
| 373 | CordVtnNode node = nodeByBridgeId(deviceId); |
| 374 | if (node == null) { |
| 375 | log.warn("Failed to get node for {}", deviceId); |
| 376 | return null; |
| 377 | } |
| 378 | |
| 379 | if (node.hostMgmtIface().isPresent()) { |
| 380 | Optional<PortNumber> port = getPortNumber(deviceId, node.hostMgmtIface().get()); |
| 381 | return port.isPresent() ? port.get() : null; |
| 382 | } else { |
| 383 | return null; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | private Optional<PortNumber> getPortNumber(DeviceId deviceId, String portName) { |
| 388 | PortNumber port = deviceService.getPorts(deviceId).stream() |
| 389 | .filter(p -> p.annotations().value(AnnotationKeys.PORT_NAME).equals(portName) && |
| 390 | p.isEnabled()) |
| 391 | .map(Port::number) |
| 392 | .findAny() |
| 393 | .orElse(null); |
| 394 | return Optional.ofNullable(port); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Returns if current node state saved in nodeStore is COMPLETE or not. |
| 399 | * |
| 400 | * @param node cordvtn node |
| 401 | * @return true if it's complete state, otherwise false |
| 402 | */ |
| 403 | private boolean isNodeStateComplete(CordVtnNode node) { |
| 404 | checkNotNull(node); |
| 405 | |
| 406 | // the state saved in nodeStore can be wrong if IP address settings are changed |
| 407 | // after the node init has been completed since there's no way to detect it |
| 408 | // getNodeState and checkNodeInitState always return correct answer but can be slow |
| 409 | Versioned<CordVtnNode> versionedNode = nodeStore.get(node.hostname()); |
| 410 | CordVtnNodeState state = versionedNode.value().state(); |
| 411 | return state != null && state.equals(NodeState.COMPLETE); |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Initiates node to serve virtual tenant network. |
| 416 | * |
| 417 | * @param node cordvtn node |
| 418 | */ |
| 419 | private void initNode(CordVtnNode node) { |
| 420 | checkNotNull(node); |
| 421 | |
| 422 | NodeState state = (NodeState) node.state(); |
| 423 | log.debug("Processing node: {} state: {}", node.hostname(), state); |
| 424 | |
| 425 | state.process(this, node); |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Performs tasks after node initialization. |
| 430 | * It disconnects unnecessary OVSDB connection and installs initial flow |
| 431 | * rules on the device. |
| 432 | * |
| 433 | * @param node cordvtn node |
| 434 | */ |
| 435 | private void postInit(CordVtnNode node) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 436 | checkNotNull(node); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 437 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 438 | // disconnect OVSDB session once the node bootstrap is done |
| 439 | OvsdbClientService ovsdbClient = getOvsdbClient(node); |
| 440 | if (ovsdbClient != null && ovsdbClient.isConnected()) { |
| 441 | ovsdbClient.disconnect(); |
| 442 | } |
| 443 | |
Hyunsun Moon | c031d9b | 2016-08-04 13:57:22 -0700 | [diff] [blame] | 444 | pipeline.initPipeline(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 445 | |
| 446 | // adds existing instances to the host list |
| 447 | deviceService.getPorts(node.integrationBridgeId()).stream() |
Hyunsun Moon | 1e88fef | 2016-08-04 14:00:35 -0700 | [diff] [blame] | 448 | .filter(port -> !node.systemIfaces().contains(portName(port)) && |
| 449 | !port.number().equals(PortNumber.LOCAL) && |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 450 | port.isEnabled()) |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 451 | .forEach(port -> instanceService.addInstance(connectPoint(port))); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 452 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 453 | // removes stale instances from the host list |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 454 | hostService.getHosts().forEach(host -> { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 455 | if (deviceService.getPort( |
| 456 | host.location().deviceId(), |
| 457 | host.location().port()) == null) { |
| 458 | instanceService.removeInstance(host.location()); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 459 | } |
| 460 | }); |
| 461 | |
| 462 | log.info("Finished init {}", node.hostname()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /** |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 466 | * Sets a new state for a given cordvtn node. |
| 467 | * |
| 468 | * @param node cordvtn node |
| 469 | * @param newState new node state |
| 470 | */ |
| 471 | private void setNodeState(CordVtnNode node, NodeState newState) { |
| 472 | checkNotNull(node); |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 473 | log.debug("Changed {} state: {}", node.hostname(), newState); |
Hyunsun Moon | 58ddbdc | 2016-03-07 16:37:17 -0800 | [diff] [blame] | 474 | nodeStore.put(node.hostname(), CordVtnNode.getUpdatedNode(node, newState)); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Checks current state of a given cordvtn node and returns it. |
| 479 | * |
| 480 | * @param node cordvtn node |
| 481 | * @return node state |
| 482 | */ |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 483 | private NodeState getNodeState(CordVtnNode node) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 484 | checkNotNull(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 485 | if (!isIntegrationBridgeCreated(node)) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 486 | return NodeState.INIT; |
| 487 | } |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 488 | for (String iface : node.systemIfaces()) { |
| 489 | if (!isIfaceCreated(node, iface)) { |
| 490 | return NodeState.BRIDGE_CREATED; |
| 491 | } |
| 492 | } |
| 493 | if (!isIpAddressSet(node)) { |
| 494 | return NodeState.PORTS_ADDED; |
| 495 | } |
| 496 | return NodeState.COMPLETE; |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /** |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 500 | * Returns connection state of OVSDB server for a given node. |
| 501 | * |
| 502 | * @param node cordvtn node |
| 503 | * @return true if it is connected, false otherwise |
| 504 | */ |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 505 | private boolean isOvsdbConnected(CordVtnNode node) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 506 | checkNotNull(node); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 507 | OvsdbClientService ovsdbClient = getOvsdbClient(node); |
| 508 | return deviceService.isAvailable(node.ovsdbId()) && |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 509 | ovsdbClient != null && |
| 510 | ovsdbClient.isConnected(); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Connects to OVSDB server for a given node. |
| 515 | * |
| 516 | * @param node cordvtn node |
| 517 | */ |
| 518 | private void connectOvsdb(CordVtnNode node) { |
| 519 | checkNotNull(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 520 | ovsdbController.connect(node.hostMgmtIp().ip(), node.ovsdbPort()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Returns OVSDB client for a given node. |
| 525 | * |
| 526 | * @param node cordvtn node |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 527 | * @return ovsdb client, or null if there's no ovsdb connection |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 528 | */ |
| 529 | private OvsdbClientService getOvsdbClient(CordVtnNode node) { |
| 530 | checkNotNull(node); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 531 | OvsdbNodeId ovsdb = new OvsdbNodeId( |
| 532 | node.hostMgmtIp().ip(), node.ovsdbPort().toInt()); |
| 533 | return ovsdbController.getOvsdbClient(ovsdb); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 534 | } |
| 535 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 536 | private void createIntegrationBridge(CordVtnNode node) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 537 | Device device = deviceService.getDevice(node.ovsdbId()); |
| 538 | if (device == null || !device.is(BridgeConfig.class)) { |
| 539 | log.error("Failed to create integration bridge on {}", node.ovsdbId()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 540 | return; |
| 541 | } |
| 542 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 543 | List<ControllerInfo> controllers = clusterService.getNodes().stream() |
| 544 | .map(controller -> new ControllerInfo(controller.ip(), OF_PORT, "tcp")) |
| 545 | .collect(Collectors.toList()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 546 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 547 | String dpid = node.integrationBridgeId().toString().substring(DPID_BEGIN); |
| 548 | BridgeDescription bridgeDesc = DefaultBridgeDescription.builder() |
| 549 | .name(INTEGRATION_BRIDGE) |
| 550 | .failMode(BridgeDescription.FailMode.SECURE) |
| 551 | .datapathId(dpid) |
| 552 | .disableInBand() |
| 553 | .controllers(controllers) |
| 554 | .build(); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 555 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 556 | BridgeConfig bridgeConfig = device.as(BridgeConfig.class); |
| 557 | bridgeConfig.addBridge(bridgeDesc); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 560 | private void createTunnelInterface(CordVtnNode node) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 561 | Device device = deviceService.getDevice(node.ovsdbId()); |
| 562 | if (device == null || !device.is(InterfaceConfig.class)) { |
| 563 | log.error("Failed to create tunnel interface on {}", node.ovsdbId()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 564 | return; |
| 565 | } |
| 566 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 567 | TunnelDescription tunnelDesc = DefaultTunnelDescription.builder() |
| 568 | .deviceId(INTEGRATION_BRIDGE) |
| 569 | .ifaceName(DEFAULT_TUNNEL) |
| 570 | .type(VXLAN) |
| 571 | .remote(TunnelEndPoints.flowTunnelEndpoint()) |
| 572 | .key(TunnelKeys.flowTunnelKey()) |
| 573 | .build(); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 574 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 575 | InterfaceConfig ifaceConfig = device.as(InterfaceConfig.class); |
| 576 | ifaceConfig.addTunnelMode(DEFAULT_TUNNEL, tunnelDesc); |
Hyunsun Moon | bd572c1 | 2016-01-21 00:54:52 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 579 | private void addSystemInterface(CordVtnNode node, String ifaceName) { |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 580 | Session session = connect(node.sshInfo()); |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 581 | if (session == null || !isInterfaceUp(session, ifaceName)) { |
| 582 | log.warn("Interface {} is not available on {}", ifaceName, node.hostname()); |
| 583 | disconnect(session); |
| 584 | return; |
| 585 | } else { |
| 586 | disconnect(session); |
| 587 | } |
| 588 | |
| 589 | Device device = deviceService.getDevice(node.ovsdbId()); |
| 590 | if (!device.is(BridgeConfig.class)) { |
| 591 | log.error("BridgeConfig is not supported for {}", node.ovsdbId()); |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 592 | return; |
| 593 | } |
| 594 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 595 | BridgeConfig bridgeConfig = device.as(BridgeConfig.class); |
| 596 | bridgeConfig.addPort(BridgeName.bridgeName(INTEGRATION_BRIDGE), ifaceName); |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Flushes IP address from data plane interface and adds data plane IP address |
| 601 | * to integration bridge. |
| 602 | * |
| 603 | * @param node cordvtn node |
| 604 | */ |
| 605 | private void setIpAddress(CordVtnNode node) { |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 606 | Session session = connect(node.sshInfo()); |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 607 | if (session == null) { |
| 608 | log.debug("Failed to SSH to {}", node.hostname()); |
| 609 | return; |
| 610 | } |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 611 | getCurrentIps(session, INTEGRATION_BRIDGE).stream() |
Hyunsun Moon | 0592c3d | 2016-06-23 14:47:52 -0700 | [diff] [blame] | 612 | .filter(ip -> !ip.equals(node.localMgmtIp().ip())) |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 613 | .filter(ip -> !ip.equals(node.dataIp().ip())) |
| 614 | .forEach(ip -> deleteIp(session, ip, INTEGRATION_BRIDGE)); |
Hyunsun Moon | 0592c3d | 2016-06-23 14:47:52 -0700 | [diff] [blame] | 615 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 616 | boolean result = flushIp(session, node.dataIface()) && |
| 617 | setInterfaceUp(session, node.dataIface()) && |
| 618 | addIp(session, node.dataIp(), INTEGRATION_BRIDGE) && |
| 619 | addIp(session, node.localMgmtIp(), INTEGRATION_BRIDGE) && |
| 620 | setInterfaceUp(session, INTEGRATION_BRIDGE); |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 621 | |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 622 | disconnect(session); |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 623 | if (result) { |
| 624 | setNodeState(node, NodeState.COMPLETE); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 628 | private boolean isIntegrationBridgeCreated(CordVtnNode node) { |
| 629 | return deviceService.getDevice(node.integrationBridgeId()) != null && |
| 630 | deviceService.isAvailable(node.integrationBridgeId()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 633 | private boolean isIfaceCreated(CordVtnNode node, String ifaceName) { |
| 634 | if (Strings.isNullOrEmpty(ifaceName)) { |
| 635 | return false; |
| 636 | } |
| 637 | return deviceService.getPorts(node.integrationBridgeId()).stream() |
| 638 | .filter(p -> portName(p).contains(ifaceName) && |
| 639 | p.isEnabled()) |
| 640 | .findAny() |
| 641 | .isPresent(); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /** |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 645 | * Checks if the IP addresses are correctly set. |
| 646 | * |
| 647 | * @param node cordvtn node |
| 648 | * @return true if the IP is set, false otherwise |
| 649 | */ |
| 650 | private boolean isIpAddressSet(CordVtnNode node) { |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 651 | Session session = connect(node.sshInfo()); |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 652 | if (session == null) { |
| 653 | log.debug("Failed to SSH to {}", node.hostname()); |
| 654 | return false; |
| 655 | } |
| 656 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 657 | Set<IpAddress> intBrIps = getCurrentIps(session, INTEGRATION_BRIDGE); |
| 658 | boolean result = getCurrentIps(session, node.dataIface()).isEmpty() && |
| 659 | isInterfaceUp(session, node.dataIface()) && |
| 660 | intBrIps.contains(node.dataIp().ip()) && |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 661 | intBrIps.contains(node.localMgmtIp().ip()) && |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 662 | isInterfaceUp(session, INTEGRATION_BRIDGE); |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 663 | |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 664 | disconnect(session); |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 665 | return result; |
| 666 | } |
| 667 | |
| 668 | /** |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 669 | * Returns connect point of a given port. |
| 670 | * |
| 671 | * @param port port |
| 672 | * @return connect point |
| 673 | */ |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 674 | private ConnectPoint connectPoint(Port port) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 675 | return new ConnectPoint(port.element().id(), port.number()); |
| 676 | } |
| 677 | |
| 678 | /** |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 679 | * Returns cordvtn node associated with a given OVSDB device. |
| 680 | * |
| 681 | * @param ovsdbId OVSDB device id |
| 682 | * @return cordvtn node, null if it fails to find the node |
| 683 | */ |
| 684 | private CordVtnNode nodeByOvsdbId(DeviceId ovsdbId) { |
| 685 | return getNodes().stream() |
| 686 | .filter(node -> node.ovsdbId().equals(ovsdbId)) |
| 687 | .findFirst().orElse(null); |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Returns cordvtn node associated with a given integration bridge. |
| 692 | * |
| 693 | * @param bridgeId device id of integration bridge |
| 694 | * @return cordvtn node, null if it fails to find the node |
| 695 | */ |
| 696 | private CordVtnNode nodeByBridgeId(DeviceId bridgeId) { |
| 697 | return getNodes().stream() |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 698 | .filter(node -> node.integrationBridgeId().equals(bridgeId)) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 699 | .findFirst().orElse(null); |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Returns port name. |
| 704 | * |
| 705 | * @param port port |
| 706 | * @return port name |
| 707 | */ |
| 708 | private String portName(Port port) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 709 | return port.annotations().value(PORT_NAME); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 712 | private class OvsdbHandler implements ConnectionHandler<Device> { |
| 713 | |
| 714 | @Override |
| 715 | public void connected(Device device) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 716 | CordVtnNode node = nodeByOvsdbId(device.id()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 717 | if (node != null) { |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 718 | setNodeState(node, getNodeState(node)); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 719 | } else { |
| 720 | log.debug("{} is detected on unregistered node, ignore it.", device.id()); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | @Override |
| 725 | public void disconnected(Device device) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 726 | log.debug("Device {} is disconnected", device.id()); |
| 727 | adminService.removeDevice(device.id()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
| 731 | private class BridgeHandler implements ConnectionHandler<Device> { |
| 732 | |
| 733 | @Override |
| 734 | public void connected(Device device) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 735 | CordVtnNode node = nodeByBridgeId(device.id()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 736 | if (node != null) { |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 737 | setNodeState(node, getNodeState(node)); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 738 | } else { |
| 739 | log.debug("{} is detected on unregistered node, ignore it.", device.id()); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | @Override |
| 744 | public void disconnected(Device device) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 745 | CordVtnNode node = nodeByBridgeId(device.id()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 746 | if (node != null) { |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 747 | log.warn("Integration Bridge is disconnected from {}", node.hostname()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 748 | setNodeState(node, NodeState.INCOMPLETE); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /** |
| 753 | * Handles port added situation. |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 754 | * If the added port is tunnel or data plane interface, proceed to the remaining |
| 755 | * node initialization. Otherwise, do nothing. |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 756 | * |
| 757 | * @param port port |
| 758 | */ |
| 759 | public void portAdded(Port port) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 760 | CordVtnNode node = nodeByBridgeId((DeviceId) port.element().id()); |
| 761 | String portName = portName(port); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 762 | |
| 763 | if (node == null) { |
| 764 | log.debug("{} is added to unregistered node, ignore it.", portName); |
| 765 | return; |
| 766 | } |
| 767 | |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 768 | log.info("Port {} is added to {}", portName, node.hostname()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 769 | |
Hyunsun Moon | 1e88fef | 2016-08-04 14:00:35 -0700 | [diff] [blame] | 770 | if (node.systemIfaces().contains(portName)) { |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 771 | setNodeState(node, getNodeState(node)); |
Hyunsun Moon | 1e88fef | 2016-08-04 14:00:35 -0700 | [diff] [blame] | 772 | } else if (isNodeStateComplete(node)) { |
| 773 | instanceService.addInstance(connectPoint(port)); |
| 774 | } else { |
| 775 | log.warn("Instance is detected on incomplete node, ignore it.", portName); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | /** |
| 780 | * Handles port removed situation. |
Hyunsun Moon | 126171d | 2016-02-09 01:55:48 -0800 | [diff] [blame] | 781 | * If the removed port is tunnel or data plane interface, proceed to the remaining |
| 782 | * node initialization.Others, do nothing. |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 783 | * |
| 784 | * @param port port |
| 785 | */ |
| 786 | public void portRemoved(Port port) { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 787 | CordVtnNode node = nodeByBridgeId((DeviceId) port.element().id()); |
| 788 | String portName = portName(port); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 789 | |
| 790 | if (node == null) { |
| 791 | return; |
| 792 | } |
| 793 | |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 794 | log.info("Port {} is removed from {}", portName, node.hostname()); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 795 | |
Hyunsun Moon | 1e88fef | 2016-08-04 14:00:35 -0700 | [diff] [blame] | 796 | if (node.systemIfaces().contains(portName)) { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 797 | setNodeState(node, NodeState.INCOMPLETE); |
Hyunsun Moon | 1e88fef | 2016-08-04 14:00:35 -0700 | [diff] [blame] | 798 | } else if (isNodeStateComplete(node)) { |
| 799 | instanceService.removeInstance(connectPoint(port)); |
| 800 | } else { |
| 801 | log.warn("VM is vanished from incomplete node, ignore it.", portName); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | private class InternalDeviceListener implements DeviceListener { |
| 807 | |
| 808 | @Override |
| 809 | public void event(DeviceEvent event) { |
| 810 | |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 811 | NodeId leaderNodeId = leadershipService.getLeader(appId.name()); |
| 812 | if (!Objects.equals(localNodeId, leaderNodeId)) { |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 813 | // do not allow to proceed without leadership |
Hyunsun Moon | 7004fcf | 2016-03-08 04:36:02 -0800 | [diff] [blame] | 814 | return; |
| 815 | } |
| 816 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 817 | Device device = event.subject(); |
| 818 | ConnectionHandler<Device> handler = |
| 819 | (device.type().equals(SWITCH) ? bridgeHandler : ovsdbHandler); |
| 820 | |
| 821 | switch (event.type()) { |
| 822 | case PORT_ADDED: |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 823 | eventExecutor.execute(() -> bridgeHandler.portAdded(event.port())); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 824 | break; |
| 825 | case PORT_UPDATED: |
| 826 | if (!event.port().isEnabled()) { |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 827 | eventExecutor.execute(() -> bridgeHandler.portRemoved(event.port())); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 828 | } |
| 829 | break; |
| 830 | case DEVICE_ADDED: |
| 831 | case DEVICE_AVAILABILITY_CHANGED: |
| 832 | if (deviceService.isAvailable(device.id())) { |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 833 | eventExecutor.execute(() -> handler.connected(device)); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 834 | } else { |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 835 | eventExecutor.execute(() -> handler.disconnected(device)); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 836 | } |
| 837 | break; |
| 838 | default: |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | /** |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 845 | * Reads cordvtn nodes from config file. |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 846 | */ |
| 847 | private void readConfiguration() { |
| 848 | CordVtnConfig config = configRegistry.getConfig(appId, CordVtnConfig.class); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 849 | if (config == null) { |
Hyunsun Moon | 3fc17f7 | 2016-01-24 21:47:06 -0800 | [diff] [blame] | 850 | log.debug("No configuration found"); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 851 | return; |
| 852 | } |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 853 | config.cordVtnNodes().forEach(this::addOrUpdateNode); |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | private class InternalConfigListener implements NetworkConfigListener { |
| 857 | |
| 858 | @Override |
| 859 | public void event(NetworkConfigEvent event) { |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 860 | NodeId leaderNodeId = leadershipService.getLeader(appId.name()); |
| 861 | if (!Objects.equals(localNodeId, leaderNodeId)) { |
| 862 | // do not allow to proceed without leadership |
| 863 | return; |
| 864 | } |
| 865 | |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 866 | if (!event.configClass().equals(CordVtnConfig.class)) { |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | switch (event.type()) { |
| 871 | case CONFIG_ADDED: |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 872 | case CONFIG_UPDATED: |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 873 | eventExecutor.execute(CordVtnNodeManager.this::readConfiguration); |
| 874 | break; |
| 875 | default: |
| 876 | break; |
| 877 | } |
| 878 | } |
| 879 | } |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 880 | |
| 881 | private class InternalMapListener implements MapEventListener<String, CordVtnNode> { |
| 882 | |
| 883 | @Override |
| 884 | public void event(MapEvent<String, CordVtnNode> event) { |
| 885 | NodeId leaderNodeId = leadershipService.getLeader(appId.name()); |
| 886 | if (!Objects.equals(localNodeId, leaderNodeId)) { |
| 887 | // do not allow to proceed without leadership |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | CordVtnNode oldNode; |
| 892 | CordVtnNode newNode; |
| 893 | |
| 894 | switch (event.type()) { |
| 895 | case UPDATE: |
| 896 | oldNode = event.oldValue().value(); |
| 897 | newNode = event.newValue().value(); |
| 898 | |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 899 | log.info("Reloaded {}", newNode.hostname()); |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 900 | if (!newNode.equals(oldNode)) { |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 901 | log.debug("New node: {}", newNode); |
| 902 | } |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 903 | // performs init procedure even if the node is not changed |
| 904 | // for robustness since it's no harm to run init procedure |
| 905 | // multiple times |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 906 | eventExecutor.execute(() -> initNode(newNode)); |
| 907 | break; |
| 908 | case INSERT: |
| 909 | newNode = event.newValue().value(); |
| 910 | log.info("Added {}", newNode.hostname()); |
| 911 | eventExecutor.execute(() -> initNode(newNode)); |
| 912 | break; |
| 913 | case REMOVE: |
| 914 | oldNode = event.oldValue().value(); |
Hyunsun Moon | 479b775 | 2016-05-06 20:13:28 -0700 | [diff] [blame] | 915 | log.info("Removed {}", oldNode.hostname()); |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 916 | break; |
| 917 | default: |
| 918 | break; |
| 919 | } |
| 920 | } |
| 921 | } |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 922 | } |