blob: 79526e6d7e2e069997e8f206205002bc2157052f [file] [log] [blame]
Daniel Parkc4d06402018-05-28 15:57:37 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.openstacknode.util;
17
18import org.onosproject.net.device.DeviceService;
19import org.onosproject.openstacknode.api.OpenstackNode;
20import org.onosproject.ovsdb.controller.OvsdbClientService;
21import org.onosproject.ovsdb.controller.OvsdbController;
22import org.onosproject.ovsdb.controller.OvsdbNodeId;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26/**
27 * An utility that used in openstack node app.
28 */
29public final class OpenstackNodeUtil {
30 protected static final Logger log = LoggerFactory.getLogger(OpenstackNodeUtil.class);
31
32 /**
33 * Prevents object instantiation from external.
34 */
35 private OpenstackNodeUtil() {
36 }
37
38 /**
39 * Checks whether the controller has a connection with an OVSDB that resides
40 * inside the given openstack node.
41 *
42 * @param osNode openstack node
43 * @param ovsdbPort ovsdb port
44 * @param ovsdbController ovsdb controller
45 * @param deviceService device service
46 * @return true if the controller is connected to the OVSDB, false otherwise
47 */
48 public static boolean isOvsdbConnected(OpenstackNode osNode,
49 int ovsdbPort,
50 OvsdbController ovsdbController,
51 DeviceService deviceService) {
52 OvsdbNodeId ovsdb = new OvsdbNodeId(osNode.managementIp(), ovsdbPort);
53 OvsdbClientService client = ovsdbController.getOvsdbClient(ovsdb);
54 return deviceService.isAvailable(osNode.ovsdb()) &&
55 client != null &&
56 client.isConnected();
57 }
58}