Committed by
Gerrit Code Review
[ONOS-4939] NETCONF function for FUJITSU OLT #7
- Add "ONU firmware upgrade" command for FUJITSU OLT volt-ondemandfwdl <netconf:target> <Firmware Image name:ONU-ID list[:reboot-mode]> - Update fujitsu-drivers.xml and shell-config.xml in FUJITSU directory Change-Id: Id90c4a59046e0a0f695ddcd40ea3ab905d1fa253
Showing
5 changed files
with
228 additions
and
0 deletions
1 | +/* | ||
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 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | +import org.onosproject.drivers.fujitsu.behaviour.VoltFwdlConfig; | ||
20 | +import org.onosproject.mastership.MastershipService; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
23 | +import org.onosproject.net.driver.DriverHandler; | ||
24 | +import org.onosproject.netconf.NetconfController; | ||
25 | +import org.slf4j.Logger; | ||
26 | + | ||
27 | +import java.io.IOException; | ||
28 | + | ||
29 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
30 | +import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*; | ||
31 | +import static org.slf4j.LoggerFactory.getLogger; | ||
32 | + | ||
33 | +/** | ||
34 | + * Implementation to upgrade firmware in ONUs manually | ||
35 | + * through the Netconf protocol. | ||
36 | + */ | ||
37 | +public class FujitsuVoltFwdlConfig extends AbstractHandlerBehaviour | ||
38 | + implements VoltFwdlConfig { | ||
39 | + | ||
40 | + private final Logger log = getLogger(FujitsuVoltFwdlConfig.class); | ||
41 | + private static final String ONDEMAND_FIRMWARE_UPGRADE = "ondemand-firmware-upgrade"; | ||
42 | + private static final String PARTICIPANT_LIST = "participant-list"; | ||
43 | + private static final String MEMBER = "member"; | ||
44 | + private static final String IMAGE_NAME = "image-name"; | ||
45 | + private static final String REBOOT_MODE = "reboot-mode"; | ||
46 | + private int pon; | ||
47 | + private int onu; | ||
48 | + | ||
49 | + | ||
50 | + @Override | ||
51 | + public String upgradeFirmwareOndemand(String target) { | ||
52 | + DriverHandler handler = handler(); | ||
53 | + NetconfController controller = handler.get(NetconfController.class); | ||
54 | + MastershipService mastershipService = handler.get(MastershipService.class); | ||
55 | + DeviceId ncDeviceId = handler.data().deviceId(); | ||
56 | + checkNotNull(controller, "Netconf controller is null"); | ||
57 | + String reply = null; | ||
58 | + int count; | ||
59 | + | ||
60 | + if (!mastershipService.isLocalMaster(ncDeviceId)) { | ||
61 | + log.warn("Not master for {} Use {} to execute command", | ||
62 | + ncDeviceId, | ||
63 | + mastershipService.getMasterFor(ncDeviceId)); | ||
64 | + return reply; | ||
65 | + } | ||
66 | + | ||
67 | + String[] data = target.split(":"); | ||
68 | + if ((data.length < 2) || (data.length > 3)) { | ||
69 | + log.error("Invalid number of arguments"); | ||
70 | + return reply; | ||
71 | + } | ||
72 | + | ||
73 | + String[] onuList = data[1].split(","); | ||
74 | + if (onuList.length == 0) { | ||
75 | + log.error("No ONU listed"); | ||
76 | + return reply; | ||
77 | + } | ||
78 | + | ||
79 | + try { | ||
80 | + StringBuilder request = new StringBuilder(); | ||
81 | + request.append(ANGLE_LEFT).append(ONDEMAND_FIRMWARE_UPGRADE).append(SPACE); | ||
82 | + request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE); | ||
83 | + request.append(buildStartTag(PARTICIPANT_LIST)); | ||
84 | + | ||
85 | + for (count = 0; count < onuList.length; count++) { | ||
86 | + String[] onuId = onuList[count].split("-"); | ||
87 | + if (onuId.length != 2) { | ||
88 | + log.error("Invalid ONU identifier"); | ||
89 | + return reply; | ||
90 | + } | ||
91 | + | ||
92 | + try { | ||
93 | + pon = Integer.parseInt(onuId[0]); | ||
94 | + onu = Integer.parseInt(onuId[1]); | ||
95 | + } catch (NumberFormatException e) { | ||
96 | + log.error("Non-number input"); | ||
97 | + return reply; | ||
98 | + } | ||
99 | + | ||
100 | + request.append(buildStartTag(MEMBER)); | ||
101 | + request.append(buildStartTag(PONLINK_ID)); | ||
102 | + request.append(onuId[0]); | ||
103 | + request.append(buildEndTag(PONLINK_ID)); | ||
104 | + request.append(buildStartTag(ONU_ID)); | ||
105 | + request.append(onuId[1]); | ||
106 | + request.append(buildEndTag(ONU_ID)); | ||
107 | + request.append(buildEndTag(MEMBER)); | ||
108 | + } | ||
109 | + request.append(buildEndTag(PARTICIPANT_LIST)); | ||
110 | + request.append(buildStartTag(IMAGE_NAME)); | ||
111 | + request.append(data[0]); | ||
112 | + request.append(buildEndTag(IMAGE_NAME)); | ||
113 | + if (data.length == 3) { | ||
114 | + request.append(buildStartTag(REBOOT_MODE)); | ||
115 | + request.append(data[2]); | ||
116 | + request.append(buildEndTag(REBOOT_MODE)); | ||
117 | + } | ||
118 | + request.append(buildEndTag(ONDEMAND_FIRMWARE_UPGRADE)); | ||
119 | + | ||
120 | + reply = controller. | ||
121 | + getDevicesMap().get(ncDeviceId).getSession(). | ||
122 | + doWrappedRpc(request.toString()); | ||
123 | + } catch (IOException e) { | ||
124 | + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | ||
125 | + } | ||
126 | + return reply; | ||
127 | + } | ||
128 | + | ||
129 | +} |
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltFwdlConfig.java
0 → 100644
1 | +/* | ||
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 | +package org.onosproject.drivers.fujitsu.behaviour; | ||
17 | + | ||
18 | +import com.google.common.annotations.Beta; | ||
19 | +import org.onosproject.net.driver.HandlerBehaviour; | ||
20 | + | ||
21 | +/** | ||
22 | + * Device behaviour to upgrade ONUs to new firmware. | ||
23 | + */ | ||
24 | +@Beta | ||
25 | +public interface VoltFwdlConfig extends HandlerBehaviour { | ||
26 | + | ||
27 | + /** | ||
28 | + * Upgrade firmware manually in an ONU in the device. | ||
29 | + * | ||
30 | + * @param target input data in string | ||
31 | + */ | ||
32 | + String upgradeFirmwareOndemand(String target); | ||
33 | + | ||
34 | +} |
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltOndemandFwdlCommand.java
0 → 100644
1 | +/* | ||
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 | +package org.onosproject.drivers.fujitsu.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onosproject.cli.AbstractShellCommand; | ||
21 | +import org.onosproject.drivers.fujitsu.behaviour.VoltFwdlConfig; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.driver.DriverHandler; | ||
24 | +import org.onosproject.net.driver.DriverService; | ||
25 | + | ||
26 | +/** | ||
27 | + * Requests manual firmware upgrade on a list of ONUs in vOLT. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "volt-ondemandfwdl", | ||
30 | + description = "Requests manual firmware upgrade on a list of ONUs in vOLT") | ||
31 | +public class VoltOndemandFwdlCommand extends AbstractShellCommand { | ||
32 | + | ||
33 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
34 | + required = true, multiValued = false) | ||
35 | + String uri = null; | ||
36 | + | ||
37 | + @Argument(index = 1, name = "target", | ||
38 | + description = "image name:PON link ID-ONU ID[,PON link ID-ONU ID,..:reboot-mode]", | ||
39 | + required = true, multiValued = false) | ||
40 | + String target = null; | ||
41 | + | ||
42 | + private DeviceId deviceId; | ||
43 | + | ||
44 | + @Override | ||
45 | + protected void execute() { | ||
46 | + DriverService service = get(DriverService.class); | ||
47 | + deviceId = DeviceId.deviceId(uri); | ||
48 | + DriverHandler h = service.createHandler(deviceId); | ||
49 | + VoltFwdlConfig volt = h.behaviour(VoltFwdlConfig.class); | ||
50 | + String reply = volt.upgradeFirmwareOndemand(target); | ||
51 | + if (reply != null) { | ||
52 | + print("%s", reply); | ||
53 | + } else { | ||
54 | + print("ONU firmware-upgrade failure %s", deviceId.toString()); | ||
55 | + } | ||
56 | + } | ||
57 | +} |
... | @@ -77,6 +77,12 @@ | ... | @@ -77,6 +77,12 @@ |
77 | <ref component-id="deviceIdCompleter"/> | 77 | <ref component-id="deviceIdCompleter"/> |
78 | </completers> | 78 | </completers> |
79 | </command> | 79 | </command> |
80 | + <command> | ||
81 | + <action class="org.onosproject.drivers.fujitsu.cli.VoltOndemandFwdlCommand"/> | ||
82 | + <completers> | ||
83 | + <ref component-id="deviceIdCompleter"/> | ||
84 | + </completers> | ||
85 | + </command> | ||
80 | </command-bundle> | 86 | </command-bundle> |
81 | 87 | ||
82 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> | 88 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> | ... | ... |
... | @@ -32,5 +32,7 @@ | ... | @@ -32,5 +32,7 @@ |
32 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltOnuOperConfig"/> | 32 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltOnuOperConfig"/> |
33 | <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltAlertConfig" | 33 | <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltAlertConfig" |
34 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltAlertConfig"/> | 34 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltAlertConfig"/> |
35 | + <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltFwdlConfig" | ||
36 | + impl="org.onosproject.drivers.fujitsu.FujitsuVoltFwdlConfig"/> | ||
35 | </driver> | 37 | </driver> |
36 | </drivers> | 38 | </drivers> | ... | ... |
-
Please register or login to post a comment