blob: 67f1db2922faa8f4836e703a648f1d49e040a0eb [file] [log] [blame]
Akihiro Yamanouchi8d3a9d32016-07-12 11:41:44 +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.mastership.MastershipService;
20import org.onosproject.net.DeviceId;
21import org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig;
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 take actions on ONU available in vOLT
35 * through the Netconf protocol.
36 */
37public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour
38 implements VoltOnuOperConfig {
39
40 private final Logger log = getLogger(FujitsuVoltOnuOperConfig.class);
41 private static final String ONU_REBOOT = "onu-reboot";
42 private static final String ONU_ETHPORT_LOOPBACK = "onu-ethport-loopback";
43 private static final String ETHPORT_ID = "ethport-id";
44 private int pon;
45 private int onu;
46 private int eth;
47
48
49 @Override
50 public String rebootOnu(String target) {
51 DriverHandler handler = handler();
52 NetconfController controller = handler.get(NetconfController.class);
53 MastershipService mastershipService = handler.get(MastershipService.class);
54 DeviceId ncDeviceId = handler.data().deviceId();
55 checkNotNull(controller, "Netconf controller is null");
56 String reply = null;
57 String[] onuId = null;
58
59 if (!mastershipService.isLocalMaster(ncDeviceId)) {
60 log.warn("Not master for {} Use {} to execute command",
61 ncDeviceId,
62 mastershipService.getMasterFor(ncDeviceId));
63 return reply;
64 }
65
66 onuId = target.split(HYPHEN);
67 if (onuId.length != 2) {
68 log.error("Invalid number of arguments");
69 return reply;
70 }
71 try {
72 pon = Integer.parseInt(onuId[0]);
73 onu = Integer.parseInt(onuId[1]);
74 } catch (NumberFormatException e) {
75 log.error("Non-number input");
76 return reply;
77 }
78
79 try {
80 StringBuilder request = new StringBuilder();
81 request.append(ANGLE_LEFT).append(ONU_REBOOT).append(SPACE);
82 request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE);
83 request.append(buildStartTag(PONLINK_ID, false));
84 request.append(onuId[0]);
85 request.append(buildEndTag(PONLINK_ID));
86 request.append(buildStartTag(ONU_ID, false));
87 request.append(onuId[1]);
88 request.append(buildEndTag(ONU_ID));
89 request.append(buildEndTag(ONU_REBOOT));
90
91 reply = controller.
92 getDevicesMap().get(ncDeviceId).getSession().
93 doWrappedRpc(request.toString());
94 } catch (IOException e) {
95 log.error("Cannot communicate to device {} exception ", ncDeviceId, e);
96 }
97 return reply;
98 }
99
100 @Override
101 public String loopbackEthOnu(String target) {
102 DriverHandler handler = handler();
103 NetconfController controller = handler.get(NetconfController.class);
104 MastershipService mastershipService = handler.get(MastershipService.class);
105 DeviceId ncDeviceId = handler.data().deviceId();
106 checkNotNull(controller, "Netconf controller is null");
107 String reply = null;
108 String[] ethId = null;
109
110 if (!mastershipService.isLocalMaster(ncDeviceId)) {
111 log.warn("Not master for {} Use {} to execute command",
112 ncDeviceId,
113 mastershipService.getMasterFor(ncDeviceId));
114 return reply;
115 }
116
117 ethId = target.split(HYPHEN);
118 if (ethId.length != 3) {
119 log.error("Invalid number of arguments");
120 return reply;
121 }
122 try {
123 pon = Integer.parseInt(ethId[0]);
124 onu = Integer.parseInt(ethId[1]);
125 eth = Integer.parseInt(ethId[2]);
126 } catch (NumberFormatException e) {
127 log.error("Non-number input");
128 return reply;
129 }
130
131 try {
132 StringBuilder request = new StringBuilder();
133 request.append(ANGLE_LEFT).append(ONU_ETHPORT_LOOPBACK).append(SPACE);
134 request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE);
135 request.append(buildStartTag(PONLINK_ID, false));
136 request.append(ethId[0]);
137 request.append(buildEndTag(PONLINK_ID));
138 request.append(buildStartTag(ONU_ID, false));
139 request.append(ethId[1]);
140 request.append(buildEndTag(ONU_ID));
141 request.append(buildStartTag(ETHPORT_ID, false));
142 request.append(ethId[2]);
143 request.append(buildEndTag(ETHPORT_ID));
144 request.append(buildEndTag(ONU_ETHPORT_LOOPBACK));
145
146 reply = controller.
147 getDevicesMap().get(ncDeviceId).getSession().
148 doWrappedRpc(request.toString());
149 } catch (IOException e) {
150 log.error("Cannot communicate to device {} exception ", ncDeviceId, e);
151 }
152 return reply;
153 }
154
155}