Committed by
Gerrit Code Review
[ONOS-4990] NETCONF function for FUJITSU OLT #8
- Add a command to get all configuration from FJ OLT. e.g. volt-all <netconf: target> Change-Id: I70b4cf8851ce1911569ca62e59ec40df48913d88
Showing
5 changed files
with
169 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.VoltNeConfig; | ||
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 get all available data in vOLT | ||
35 | + * through the Netconf protocol. | ||
36 | + */ | ||
37 | +public 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 | +} |
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltNeConfig.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 get all available data in vOLT. | ||
23 | + */ | ||
24 | +@Beta | ||
25 | +public interface VoltNeConfig extends HandlerBehaviour { | ||
26 | + | ||
27 | + /** | ||
28 | + * Obtain all available data in the device. | ||
29 | + * | ||
30 | + * @return response string | ||
31 | + */ | ||
32 | + String getAll(); | ||
33 | + | ||
34 | +} |
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.VoltNeConfig; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.driver.DriverHandler; | ||
24 | +import org.onosproject.net.driver.DriverService; | ||
25 | + | ||
26 | +/** | ||
27 | + * Gets all available data in vOLT. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "volt-all", | ||
30 | + description = "Gets all available data in vOLT") | ||
31 | +public class VoltGetAllCommand extends AbstractShellCommand { | ||
32 | + | ||
33 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
34 | + required = true, multiValued = false) | ||
35 | + String uri = null; | ||
36 | + | ||
37 | + private DeviceId deviceId; | ||
38 | + | ||
39 | + @Override | ||
40 | + protected void execute() { | ||
41 | + DriverService service = get(DriverService.class); | ||
42 | + deviceId = DeviceId.deviceId(uri); | ||
43 | + DriverHandler h = service.createHandler(deviceId); | ||
44 | + VoltNeConfig volt = h.behaviour(VoltNeConfig.class); | ||
45 | + String reply = volt.getAll(); | ||
46 | + if (reply != null) { | ||
47 | + print("%s", reply); | ||
48 | + } else { | ||
49 | + print("No reply from %s", deviceId.toString()); | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | +} |
... | @@ -83,6 +83,12 @@ | ... | @@ -83,6 +83,12 @@ |
83 | <ref component-id="deviceIdCompleter"/> | 83 | <ref component-id="deviceIdCompleter"/> |
84 | </completers> | 84 | </completers> |
85 | </command> | 85 | </command> |
86 | + <command> | ||
87 | + <action class="org.onosproject.drivers.fujitsu.cli.VoltGetAllCommand"/> | ||
88 | + <completers> | ||
89 | + <ref component-id="deviceIdCompleter"/> | ||
90 | + </completers> | ||
91 | + </command> | ||
86 | </command-bundle> | 92 | </command-bundle> |
87 | 93 | ||
88 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> | 94 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> | ... | ... |
... | @@ -34,5 +34,7 @@ | ... | @@ -34,5 +34,7 @@ |
34 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltAlertConfig"/> | 34 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltAlertConfig"/> |
35 | <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltFwdlConfig" | 35 | <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltFwdlConfig" |
36 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltFwdlConfig"/> | 36 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltFwdlConfig"/> |
37 | + <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltNeConfig" | ||
38 | + impl="org.onosproject.drivers.fujitsu.FujitsuVoltNeConfig"/> | ||
37 | </driver> | 39 | </driver> |
38 | </drivers> | 40 | </drivers> | ... | ... |
-
Please register or login to post a comment