2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.api.diagstatus;
10 import java.io.IOException;
11 import java.net.Socket;
12 import org.opendaylight.infrautils.diagstatus.DiagStatusService;
13 import org.opendaylight.infrautils.diagstatus.ServiceDescriptor;
14 import org.opendaylight.infrautils.diagstatus.ServiceState;
15 import org.opendaylight.infrautils.diagstatus.ServiceStatusProvider;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class OpenflowPluginDiagStatusProvider implements ServiceStatusProvider {
21 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginDiagStatusProvider.class);
22 private static final String OPENFLOW_SERVICE_NAME = "OPENFLOW";
23 private static final int OF_PORT_11 = 6633;
24 private static final int OF_PORT_13 = 6653;
26 private final DiagStatusService diagStatusService;
27 private volatile ServiceDescriptor serviceDescriptor;
29 public OpenflowPluginDiagStatusProvider(final DiagStatusService diagStatusService) {
30 this.diagStatusService = diagStatusService;
31 diagStatusService.register(OPENFLOW_SERVICE_NAME);
34 public void reportStatus(ServiceState serviceState, String description) {
35 LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME);
36 serviceDescriptor = new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState, description);
37 diagStatusService.report(serviceDescriptor);
41 public ServiceDescriptor getServiceDescriptor() {
43 if (serviceDescriptor.getServiceState().equals(ServiceState.OPERATIONAL)) {
44 if (getApplicationNetworkState(OF_PORT_13) && getApplicationNetworkState(OF_PORT_11)) {
45 return serviceDescriptor;
47 serviceDescriptor = new ServiceDescriptor(OPENFLOW_SERVICE_NAME, ServiceState.ERROR,
48 "OF::PORTS:: 6653 and 6633 are not up yet");
49 return serviceDescriptor;
52 return serviceDescriptor;
55 private boolean getApplicationNetworkState(int port) {
58 socket = new Socket("localhost", port);
59 LOG.debug("Socket connection established");
61 } catch (IOException e) {
68 } catch (IOException ex) {
69 LOG.error("Failed to close socket : {}", socket, ex);