blob: 3d1c013576c3819e39e151520e18709f5b2e27c3 [file] [log] [blame]
sangho0c2a3da2016-02-16 13:39:07 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
sangho0c2a3da2016-02-16 13:39:07 +09003 *
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 */
16package org.onosproject.openstacknetworking.routing;
17
sangho6032f342016-07-07 14:32:03 +090018import org.onosproject.net.Host;
Kyuhwi Choiee9e3712016-02-22 22:49:36 +090019import org.onosproject.openstackinterface.OpenstackFloatingIP;
sangho0c2a3da2016-02-16 13:39:07 +090020
21/**
22 * Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes.
23 */
24public class OpenstackFloatingIPHandler implements Runnable {
25
sangho6032f342016-07-07 14:32:03 +090026 public enum Action {
27 ASSOCIATE,
28 DISSASSOCIATE
29 }
30
Kyuhwi Choiee9e3712016-02-22 22:49:36 +090031 private final OpenstackFloatingIP floatingIP;
32 private final OpenstackRoutingRulePopulator rulePopulator;
sangho6032f342016-07-07 14:32:03 +090033 private final Host host;
34 private final Action action;
35
Kyuhwi Choiee9e3712016-02-22 22:49:36 +090036
37 OpenstackFloatingIPHandler(OpenstackRoutingRulePopulator rulePopulator,
sangho6032f342016-07-07 14:32:03 +090038 OpenstackFloatingIP openstackFloatingIP, Action action, Host host) {
Kyuhwi Choiee9e3712016-02-22 22:49:36 +090039 this.floatingIP = openstackFloatingIP;
40 this.rulePopulator = rulePopulator;
sangho6032f342016-07-07 14:32:03 +090041 this.action = action;
42 this.host = host;
sangho0c2a3da2016-02-16 13:39:07 +090043 }
44
45 @Override
46 public void run() {
sangho6032f342016-07-07 14:32:03 +090047 if (action == Action.ASSOCIATE) {
Kyuhwi Choiee9e3712016-02-22 22:49:36 +090048 rulePopulator.populateFloatingIpRules(floatingIP);
49 } else {
sangho6032f342016-07-07 14:32:03 +090050 rulePopulator.removeFloatingIpRules(floatingIP, host);
Kyuhwi Choiee9e3712016-02-22 22:49:36 +090051 }
sangho0c2a3da2016-02-16 13:39:07 +090052 }
53}