blob: 25604880512f21abd2629bc6e6be9f9c533bd0c2 [file] [log] [blame]
Akihiro Yamanouchi237ca362016-07-29 17:34:38 +09001/*
2 * Copyright 2016-present Open Networking Laboratory
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
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;
25import org.slf4j.Logger;
26
27import java.io.IOException;
28
29import static com.google.common.base.Preconditions.checkNotNull;
30import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*;
31import static org.slf4j.LoggerFactory.getLogger;
32
33/**
34 * Implementation to get all available data in vOLT
35 * through the Netconf protocol.
36 */
37public class FujitsuVoltNeConfig extends AbstractHandlerBehaviour
38 implements VoltNeConfig {
39
40 private final Logger log = getLogger(FujitsuVoltNeConfig.class);
41
42
43 @Override
44 public String getAll() {
45 DriverHandler handler = handler();
46 NetconfController controller = handler.get(NetconfController.class);
47 MastershipService mastershipService = handler.get(MastershipService.class);
48 DeviceId ncDeviceId = handler.data().deviceId();
49 checkNotNull(controller, "Netconf controller is null");
50 String reply = null;
51
52 if (!mastershipService.isLocalMaster(ncDeviceId)) {
53 log.warn("Not master for {} Use {} to execute command",
54 ncDeviceId,
55 mastershipService.getMasterFor(ncDeviceId));
56 return reply;
57 }
58
59 try {
60 StringBuilder request = new StringBuilder();
61 request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE);
62 request.append(ANGLE_RIGHT).append(NEW_LINE);
63 request.append(VOLT_NE_CLOSE);
64
65 reply = controller.
66 getDevicesMap().get(ncDeviceId).getSession().
67 get(request.toString(), REPORT_ALL);
68 } catch (IOException e) {
69 log.error("Cannot communicate to device {} exception ", ncDeviceId, e);
70 }
71 return reply;
72 }
73
74}