blob: 90b267805162b72d0391be316443076c45da8bfb [file] [log] [blame]
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +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 */
16
17package org.onosproject.drivers.fujitsu;
18
19import org.onosproject.drivers.fujitsu.behaviour.VoltNeConfig;
20import org.onosproject.mastership.MastershipService;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.driver.AbstractHandlerBehaviour;
23import org.onosproject.net.driver.DriverHandler;
24import org.onosproject.netconf.NetconfController;
Yuta HIGUCHI234eaf32017-09-06 13:45:05 -070025import org.onosproject.netconf.NetconfException;
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +090026import org.slf4j.Logger;
27
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +090028import static com.google.common.base.Preconditions.checkNotNull;
29import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*;
30import static org.slf4j.LoggerFactory.getLogger;
31
32/**
33 * Implementation to get all available data in vOLT
34 * through the Netconf protocol.
35 */
36public class FujitsuVoltNeConfig extends AbstractHandlerBehaviour
37 implements VoltNeConfig {
38
39 private final Logger log = getLogger(FujitsuVoltNeConfig.class);
40
41
42 @Override
43 public String getAll() {
44 DriverHandler handler = handler();
45 NetconfController controller = handler.get(NetconfController.class);
46 MastershipService mastershipService = handler.get(MastershipService.class);
47 DeviceId ncDeviceId = handler.data().deviceId();
48 checkNotNull(controller, "Netconf controller is null");
49 String reply = null;
50
51 if (!mastershipService.isLocalMaster(ncDeviceId)) {
52 log.warn("Not master for {} Use {} to execute command",
53 ncDeviceId,
54 mastershipService.getMasterFor(ncDeviceId));
xueliang9e3ab182016-10-04 13:11:40 +090055 return null;
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +090056 }
57
58 try {
59 StringBuilder request = new StringBuilder();
xueliang9e3ab182016-10-04 13:11:40 +090060 request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
61 request.append(ANGLE_RIGHT + NEW_LINE);
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +090062 request.append(VOLT_NE_CLOSE);
63
xueliang9e3ab182016-10-04 13:11:40 +090064 reply = controller
65 .getDevicesMap()
66 .get(ncDeviceId)
67 .getSession()
68 .get(request.toString(), REPORT_ALL);
Yuta HIGUCHI234eaf32017-09-06 13:45:05 -070069 } catch (NetconfException e) {
xueliang9e3ab182016-10-04 13:11:40 +090070 log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +090071 }
72 return reply;
73 }
74
75}