sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
sangho | dbee233 | 2017-05-18 09:59:16 +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 | |
| 17 | package org.onosproject.openstacknetworking.impl; |
| 18 | |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 19 | import org.onlab.packet.Ethernet; |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 20 | import org.onosproject.cluster.ClusterService; |
| 21 | import org.onosproject.cluster.LeadershipService; |
| 22 | import org.onosproject.cluster.NodeId; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.CoreService; |
| 25 | import org.onosproject.net.DeviceId; |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 26 | import org.onosproject.net.Port; |
| 27 | import org.onosproject.net.device.DeviceService; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 28 | import org.onosproject.net.flow.DefaultFlowRule; |
| 29 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 31 | import org.onosproject.net.flow.FlowRule; |
| 32 | import org.onosproject.net.flow.FlowRuleOperations; |
| 33 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 34 | import org.onosproject.net.flow.FlowRuleService; |
| 35 | import org.onosproject.net.flow.TrafficSelector; |
| 36 | import org.onosproject.net.flow.TrafficTreatment; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 37 | import org.onosproject.openstacknetworking.api.Constants; |
| 38 | import org.onosproject.openstacknetworking.api.OpenstackFlowRuleService; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 39 | import org.onosproject.openstacknode.api.OpenstackNode; |
| 40 | import org.onosproject.openstacknode.api.OpenstackNodeEvent; |
| 41 | import org.onosproject.openstacknode.api.OpenstackNodeListener; |
| 42 | import org.onosproject.openstacknode.api.OpenstackNodeService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 43 | import org.osgi.service.component.annotations.Activate; |
| 44 | import org.osgi.service.component.annotations.Component; |
| 45 | import org.osgi.service.component.annotations.Deactivate; |
| 46 | import org.osgi.service.component.annotations.Reference; |
| 47 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 48 | import org.onosproject.openstacknode.api.OpenstackPhyInterface; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 49 | import org.slf4j.Logger; |
| 50 | |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 51 | import java.util.Objects; |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 52 | import java.util.Optional; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 53 | import java.util.concurrent.ExecutorService; |
| 54 | import java.util.concurrent.Executors; |
| 55 | |
| 56 | import static org.onlab.util.Tools.groupedThreads; |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 57 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
| 58 | import static org.onosproject.openstacknetworking.api.Constants.DHCP_TABLE; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 59 | import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID; |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 60 | import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FLAT_JUMP_UPSTREAM_RULE; |
| 61 | import static org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE; |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 62 | import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 63 | import static org.slf4j.LoggerFactory.getLogger; |
| 64 | |
| 65 | /** |
| 66 | * Sets flow rules directly using FlowRuleService. |
| 67 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 68 | @Component(immediate = true, service = OpenstackFlowRuleService.class) |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 69 | public class OpenstackFlowRuleManager implements OpenstackFlowRuleService { |
| 70 | |
| 71 | private final Logger log = getLogger(getClass()); |
| 72 | |
| 73 | private static final int DROP_PRIORITY = 0; |
| 74 | private static final int HIGH_PRIORITY = 30000; |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 75 | private static final int TIMEOUT_SNAT_RULE = 60; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 76 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 78 | protected FlowRuleService flowRuleService; |
| 79 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 81 | protected CoreService coreService; |
| 82 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 84 | protected ClusterService clusterService; |
| 85 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 87 | protected LeadershipService leadershipService; |
| 88 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 90 | protected OpenstackNodeService osNodeService; |
| 91 | |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 93 | protected DeviceService deviceService; |
| 94 | |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 95 | private final ExecutorService deviceEventExecutor = |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 96 | Executors.newSingleThreadExecutor(groupedThreads( |
| 97 | getClass().getSimpleName(), "device-event")); |
| 98 | private final OpenstackNodeListener internalNodeListener = |
| 99 | new InternalOpenstackNodeListener(); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 100 | |
| 101 | private ApplicationId appId; |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 102 | private NodeId localNodeId; |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 103 | |
| 104 | @Activate |
| 105 | protected void activate() { |
| 106 | appId = coreService.registerApplication(OPENSTACK_NETWORKING_APP_ID); |
| 107 | coreService.registerApplication(OPENSTACK_NETWORKING_APP_ID); |
| 108 | osNodeService.addListener(internalNodeListener); |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 109 | localNodeId = clusterService.getLocalNode().id(); |
| 110 | leadershipService.runForLeadership(appId.name()); |
| 111 | osNodeService.completeNodes(COMPUTE) |
sangho | c395d0f | 2017-07-11 10:05:25 +0900 | [diff] [blame] | 112 | .forEach(node -> initializePipeline(node.intgBridge())); |
| 113 | |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 114 | log.info("Started"); |
| 115 | } |
| 116 | |
| 117 | @Deactivate |
| 118 | protected void deactivate() { |
| 119 | osNodeService.removeListener(internalNodeListener); |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 120 | leadershipService.withdraw(appId.name()); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 121 | deviceEventExecutor.shutdown(); |
| 122 | |
| 123 | log.info("Stopped"); |
| 124 | } |
| 125 | |
| 126 | @Override |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 127 | public void setRule(ApplicationId appId, |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 128 | DeviceId deviceId, |
| 129 | TrafficSelector selector, |
| 130 | TrafficTreatment treatment, |
| 131 | int priority, |
| 132 | int tableType, |
| 133 | boolean install) { |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 134 | |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 135 | FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder() |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 136 | .forDevice(deviceId) |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 137 | .withSelector(selector) |
| 138 | .withTreatment(treatment) |
| 139 | .withPriority(priority) |
| 140 | .fromApp(appId) |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 141 | .forTable(tableType); |
| 142 | |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 143 | if (priority == Constants.PRIORITY_SNAT_RULE) { |
| 144 | flowRuleBuilder.makeTemporary(TIMEOUT_SNAT_RULE); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 145 | } else { |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 146 | flowRuleBuilder.makePermanent(); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 147 | } |
| 148 | |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 149 | applyRule(flowRuleBuilder.build(), install); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 150 | } |
| 151 | |
sangho | 3dd2a8b | 2017-07-19 15:54:31 +0900 | [diff] [blame] | 152 | @Override |
| 153 | public void connectTables(DeviceId deviceId, int fromTable, int toTable) { |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 154 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 155 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 156 | |
| 157 | treatment.transition(toTable); |
| 158 | |
| 159 | FlowRule flowRule = DefaultFlowRule.builder() |
| 160 | .forDevice(deviceId) |
| 161 | .withSelector(selector.build()) |
| 162 | .withTreatment(treatment.build()) |
| 163 | .withPriority(DROP_PRIORITY) |
| 164 | .fromApp(appId) |
| 165 | .makePermanent() |
| 166 | .forTable(fromTable) |
| 167 | .build(); |
| 168 | |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 169 | applyRule(flowRule, true); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 170 | } |
| 171 | |
sangho | 3dd2a8b | 2017-07-19 15:54:31 +0900 | [diff] [blame] | 172 | @Override |
| 173 | public void setUpTableMissEntry(DeviceId deviceId, int table) { |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 174 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 175 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 176 | |
| 177 | treatment.drop(); |
| 178 | |
| 179 | FlowRule flowRule = DefaultFlowRule.builder() |
| 180 | .forDevice(deviceId) |
| 181 | .withSelector(selector.build()) |
| 182 | .withTreatment(treatment.build()) |
| 183 | .withPriority(DROP_PRIORITY) |
| 184 | .fromApp(appId) |
| 185 | .makePermanent() |
| 186 | .forTable(table) |
| 187 | .build(); |
| 188 | |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 189 | applyRule(flowRule, true); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 190 | } |
| 191 | |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 192 | private void applyRule(FlowRule flowRule, boolean install) { |
| 193 | FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder(); |
| 194 | |
| 195 | flowOpsBuilder = install ? flowOpsBuilder.add(flowRule) : flowOpsBuilder.remove(flowRule); |
| 196 | |
| 197 | flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() { |
| 198 | @Override |
| 199 | public void onSuccess(FlowRuleOperations ops) { |
| 200 | log.debug("Provisioned vni or forwarding table"); |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public void onError(FlowRuleOperations ops) { |
| 205 | log.debug("Failed to provision vni or forwarding table"); |
| 206 | } |
| 207 | })); |
| 208 | } |
| 209 | |
| 210 | protected void initializePipeline(DeviceId deviceId) { |
| 211 | // for inbound table transition |
| 212 | connectTables(deviceId, Constants.STAT_INBOUND_TABLE, Constants.VTAP_INBOUND_TABLE); |
Jian Li | 5c09e21 | 2018-10-24 18:23:58 +0900 | [diff] [blame] | 213 | connectTables(deviceId, Constants.VTAP_INBOUND_TABLE, Constants.DHCP_TABLE); |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 214 | |
Jian Li | 5c09e21 | 2018-10-24 18:23:58 +0900 | [diff] [blame] | 215 | // for DHCP and vTag table transition |
| 216 | connectTables(deviceId, Constants.DHCP_TABLE, Constants.VTAG_TABLE); |
| 217 | |
| 218 | // for vTag and ARP table transition |
| 219 | connectTables(deviceId, Constants.VTAG_TABLE, Constants.ARP_TABLE); |
| 220 | |
| 221 | // for ARP and ACL table transition |
Jian Li | 1e9cb73 | 2018-11-25 23:17:21 +0900 | [diff] [blame] | 222 | connectTables(deviceId, Constants.ARP_TABLE, Constants.ACL_INGRESS_TABLE); |
Jian Li | 5c09e21 | 2018-10-24 18:23:58 +0900 | [diff] [blame] | 223 | |
| 224 | // for ACL and JUMP table transition |
Jian Li | 1e9cb73 | 2018-11-25 23:17:21 +0900 | [diff] [blame] | 225 | connectTables(deviceId, Constants.ACL_EGRESS_TABLE, Constants.JUMP_TABLE); |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 226 | |
| 227 | // for JUMP table transition |
| 228 | // we need JUMP table for bypassing routing table which contains large |
| 229 | // amount of flow rules which might cause performance degradation during |
| 230 | // table lookup |
| 231 | setupJumpTable(deviceId); |
| 232 | |
| 233 | // for outbound table transition |
Jian Li | 5ecfd1a | 2018-12-10 11:41:03 +0900 | [diff] [blame] | 234 | connectTables(deviceId, Constants.STAT_OUTBOUND_TABLE, |
| 235 | Constants.VTAP_OUTBOUND_TABLE); |
| 236 | connectTables(deviceId, Constants.VTAP_OUTBOUND_TABLE, |
| 237 | Constants.FORWARDING_TABLE); |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 238 | |
| 239 | // for FLAT outbound table transition |
Jian Li | 5ecfd1a | 2018-12-10 11:41:03 +0900 | [diff] [blame] | 240 | connectTables(deviceId, Constants.STAT_FLAT_OUTBOUND_TABLE, |
| 241 | Constants.VTAP_FLAT_OUTBOUND_TABLE); |
| 242 | connectTables(deviceId, Constants.VTAP_FLAT_OUTBOUND_TABLE, |
| 243 | Constants.FLAT_TABLE); |
Daniel Park | 1099d14 | 2019-02-18 17:39:56 +0900 | [diff] [blame] | 244 | |
| 245 | // for FLAT table drop |
| 246 | setUpTableMissEntry(deviceId, Constants.FLAT_TABLE); |
| 247 | |
| 248 | // for FLAT jump rules |
| 249 | if (!osNodeService.node(deviceId).phyIntfs().isEmpty()) { |
| 250 | setFlatJumpRules(deviceId); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | private void setFlatJumpRules(DeviceId deviceId) { |
| 255 | osNodeService.node(deviceId) |
| 256 | .phyIntfs() |
| 257 | .forEach(phyInterface -> |
| 258 | setFlatJumpRulesForPhyIntf(deviceId, phyInterface)); |
| 259 | } |
| 260 | |
| 261 | private void setFlatJumpRulesForPhyIntf(DeviceId deviceId, |
| 262 | OpenstackPhyInterface phyInterface) { |
| 263 | Optional<Port> phyPort = deviceService.getPorts(deviceId).stream() |
| 264 | .filter(port -> |
| 265 | Objects.equals(port.annotations().value(PORT_NAME), phyInterface.intf())) |
| 266 | .findAny(); |
| 267 | |
| 268 | phyPort.ifPresent(port -> { |
| 269 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 270 | selector.matchInPort(port.number()) |
| 271 | .matchEthType(Ethernet.TYPE_IPV4); |
| 272 | |
| 273 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 274 | treatment.transition(STAT_FLAT_OUTBOUND_TABLE); |
| 275 | FlowRule flowRuleForIp = DefaultFlowRule.builder() |
| 276 | .forDevice(deviceId) |
| 277 | .withSelector(selector.build()) |
| 278 | .withTreatment(treatment.build()) |
| 279 | .withPriority(PRIORITY_FLAT_JUMP_UPSTREAM_RULE) |
| 280 | .fromApp(appId) |
| 281 | .makePermanent() |
| 282 | .forTable(DHCP_TABLE) |
| 283 | .build(); |
| 284 | |
| 285 | applyRule(flowRuleForIp, true); |
| 286 | |
| 287 | selector = DefaultTrafficSelector.builder(); |
| 288 | selector.matchInPort(port.number()) |
| 289 | .matchEthType(Ethernet.TYPE_ARP); |
| 290 | |
| 291 | FlowRule flowRuleForArp = DefaultFlowRule.builder() |
| 292 | .forDevice(deviceId) |
| 293 | .withSelector(selector.build()) |
| 294 | .withTreatment(treatment.build()) |
| 295 | .withPriority(PRIORITY_FLAT_JUMP_UPSTREAM_RULE) |
| 296 | .fromApp(appId) |
| 297 | .makePermanent() |
| 298 | .forTable(DHCP_TABLE) |
| 299 | .build(); |
| 300 | |
| 301 | applyRule(flowRuleForArp, true); |
| 302 | }); |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 303 | } |
| 304 | |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 305 | private void setupJumpTable(DeviceId deviceId) { |
| 306 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 307 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 308 | |
| 309 | selector.matchEthDst(Constants.DEFAULT_GATEWAY_MAC); |
| 310 | treatment.transition(Constants.ROUTING_TABLE); |
| 311 | |
| 312 | FlowRule flowRule = DefaultFlowRule.builder() |
| 313 | .forDevice(deviceId) |
| 314 | .withSelector(selector.build()) |
| 315 | .withTreatment(treatment.build()) |
| 316 | .withPriority(HIGH_PRIORITY) |
| 317 | .fromApp(appId) |
| 318 | .makePermanent() |
| 319 | .forTable(Constants.JUMP_TABLE) |
| 320 | .build(); |
| 321 | |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 322 | applyRule(flowRule, true); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 323 | |
| 324 | selector = DefaultTrafficSelector.builder(); |
| 325 | treatment = DefaultTrafficTreatment.builder(); |
| 326 | |
Jian Li | 8abf2fe | 2018-06-12 18:42:30 +0900 | [diff] [blame] | 327 | treatment.transition(Constants.STAT_OUTBOUND_TABLE); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 328 | |
| 329 | flowRule = DefaultFlowRule.builder() |
| 330 | .forDevice(deviceId) |
| 331 | .withSelector(selector.build()) |
| 332 | .withTreatment(treatment.build()) |
| 333 | .withPriority(DROP_PRIORITY) |
| 334 | .fromApp(appId) |
| 335 | .makePermanent() |
| 336 | .forTable(Constants.JUMP_TABLE) |
| 337 | .build(); |
| 338 | |
sangho | dc37537 | 2017-06-08 10:41:30 +0900 | [diff] [blame] | 339 | applyRule(flowRule, true); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | private class InternalOpenstackNodeListener implements OpenstackNodeListener { |
| 343 | |
| 344 | @Override |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 345 | public boolean isRelevant(OpenstackNodeEvent event) { |
Jian Li | fb64d88 | 2018-11-27 10:57:40 +0900 | [diff] [blame] | 346 | return event.subject().type().equals(COMPUTE); |
| 347 | } |
| 348 | |
| 349 | private boolean isRelevantHelper() { |
| 350 | return Objects.equals(localNodeId, leadershipService.getLeader(appId.name())); |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | @Override |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 354 | public void event(OpenstackNodeEvent event) { |
| 355 | OpenstackNode osNode = event.subject(); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 356 | |
| 357 | switch (event.type()) { |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 358 | case OPENSTACK_NODE_COMPLETE: |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 359 | deviceEventExecutor.execute(() -> { |
| 360 | log.info("COMPLETE node {} is detected", osNode.hostname()); |
Jian Li | fb64d88 | 2018-11-27 10:57:40 +0900 | [diff] [blame] | 361 | |
| 362 | if (!isRelevantHelper()) { |
| 363 | return; |
| 364 | } |
| 365 | |
Jian Li | a077817 | 2018-07-16 22:50:19 +0900 | [diff] [blame] | 366 | initializePipeline(osNode.intgBridge()); |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 367 | }); |
| 368 | break; |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 369 | case OPENSTACK_NODE_CREATED: |
| 370 | case OPENSTACK_NODE_UPDATED: |
| 371 | case OPENSTACK_NODE_REMOVED: |
| 372 | case OPENSTACK_NODE_INCOMPLETE: |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 373 | default: |
Hyunsun Moon | 0d45736 | 2017-06-27 17:19:41 +0900 | [diff] [blame] | 374 | // do nothing |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 375 | break; |
| 376 | } |
| 377 | } |
sangho | dbee233 | 2017-05-18 09:59:16 +0900 | [diff] [blame] | 378 | } |
| 379 | } |