Committed by
Gerrit Code Review
Adding driver and behavior for getting configuration on NETCONF devices.
Change-Id: Id6986f60e8c3db0d8295576b856c04c82ae0edcb
Showing
5 changed files
with
142 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2015 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.cli.net; | ||
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.net.DeviceId; | ||
22 | +import org.onosproject.net.behaviour.ConfigGetter; | ||
23 | +import org.onosproject.net.driver.DriverHandler; | ||
24 | +import org.onosproject.net.driver.DriverService; | ||
25 | + | ||
26 | +/** | ||
27 | + * Command that gets the configuration of the specified type from the specified | ||
28 | + * device. If configuration cannot be retrieved it prints an error string. | ||
29 | + * | ||
30 | + * This is a temporary development tool for use until yang integration is complete. | ||
31 | + * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE. | ||
32 | + */ | ||
33 | + | ||
34 | +//FIXME this should eventually be removed. | ||
35 | + | ||
36 | +@Command(scope = "onos", name = "device-configuration", | ||
37 | + description = "Gets the configuration of the specified type from the" + | ||
38 | + "specified device.") | ||
39 | +public class DeviceConfigGetterCommand extends AbstractShellCommand { | ||
40 | + | ||
41 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
42 | + required = true, multiValued = false) | ||
43 | + String uri = null; | ||
44 | + @Argument(index = 1, name = "cfgType", description = "Configuration type", | ||
45 | + required = true, multiValued = false) | ||
46 | + String cfgType = null; | ||
47 | + private DeviceId deviceId; | ||
48 | + | ||
49 | + @Override | ||
50 | + protected void execute() { | ||
51 | + DriverService service = get(DriverService.class); | ||
52 | + deviceId = DeviceId.deviceId(uri); | ||
53 | + DriverHandler h = service.createHandler(deviceId); | ||
54 | + ConfigGetter config = h.behaviour(ConfigGetter.class); | ||
55 | + print(config.getConfiguration(cfgType)); | ||
56 | + } | ||
57 | + | ||
58 | +} |
... | @@ -121,6 +121,12 @@ | ... | @@ -121,6 +121,12 @@ |
121 | </completers> | 121 | </completers> |
122 | </command> | 122 | </command> |
123 | <command> | 123 | <command> |
124 | + <action class="org.onosproject.cli.net.DeviceConfigGetterCommand"/> | ||
125 | + <completers> | ||
126 | + <ref component-id="deviceIdCompleter"/> | ||
127 | + </completers> | ||
128 | + </command> | ||
129 | + <command> | ||
124 | <action class="org.onosproject.cli.net.DeviceRemoveCommand"/> | 130 | <action class="org.onosproject.cli.net.DeviceRemoveCommand"/> |
125 | <completers> | 131 | <completers> |
126 | <ref component-id="deviceIdCompleter"/> | 132 | <ref component-id="deviceIdCompleter"/> | ... | ... |
1 | +package org.onosproject.net.behaviour; | ||
2 | + | ||
3 | +import org.onosproject.net.driver.HandlerBehaviour; | ||
4 | + | ||
5 | +/** | ||
6 | + * Behaviour that gets the configuration of the specified type from the device. | ||
7 | + * | ||
8 | + * This is a temporary development tool for use until yang integration is complete. | ||
9 | + * This is not a properly specified behavior. DO NOT USE AS AN EXAMPLE. | ||
10 | + */ | ||
11 | +//FIXME this should eventually be removed. | ||
12 | +public interface ConfigGetter extends HandlerBehaviour { | ||
13 | + | ||
14 | + /** | ||
15 | + * Returns the string representation of a device configuration, returns a | ||
16 | + * failure string if the configuration cannot be retreived. | ||
17 | + * @param type the type of configuration to get (i.e. running). | ||
18 | + * @return string representation of the configuration or an error string. | ||
19 | + */ | ||
20 | + public String getConfiguration(String type); | ||
21 | +} |
1 | +package org.onosproject.driver.netconf; | ||
2 | + | ||
3 | +import com.google.common.base.Preconditions; | ||
4 | +import org.onosproject.net.DeviceId; | ||
5 | +import org.onosproject.net.behaviour.ConfigGetter; | ||
6 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
7 | +import org.onosproject.net.driver.DriverHandler; | ||
8 | +import org.onosproject.netconf.NetconfController; | ||
9 | +import org.slf4j.Logger; | ||
10 | + | ||
11 | +import java.io.IOException; | ||
12 | + | ||
13 | +import static org.slf4j.LoggerFactory.getLogger; | ||
14 | + | ||
15 | +/** | ||
16 | + * Gets the configuration of the specified type from the specified device. If a | ||
17 | + * failure occurs it returns the error string found in UNABLE_TO_READ_CONFIG. | ||
18 | + * | ||
19 | + * This is a temporary development tool for use until yang integration is complete. | ||
20 | + * This is not a properly specified behavior implementation. DO NOT USE AS AN EXAMPLE. | ||
21 | + */ | ||
22 | +//FIXME this should eventually be removed. | ||
23 | + | ||
24 | +public class NetconfConfigGetter extends AbstractHandlerBehaviour | ||
25 | + implements ConfigGetter { | ||
26 | + | ||
27 | + private final Logger log = getLogger(NetconfControllerConfig.class); | ||
28 | + | ||
29 | + //FIXME the error string should be universal for all implementations of | ||
30 | + // ConfigGetter | ||
31 | + public static final String UNABLE_TO_READ_CONFIG = "config retrieval error"; | ||
32 | + | ||
33 | + @Override | ||
34 | + public String getConfiguration(String type) { | ||
35 | + DriverHandler handler = handler(); | ||
36 | + NetconfController controller = handler.get(NetconfController.class); | ||
37 | + DeviceId ofDeviceId = handler.data().deviceId(); | ||
38 | + Preconditions.checkNotNull(controller, "Netconf controller is null"); | ||
39 | + try { | ||
40 | + return controller.getDevicesMap(). | ||
41 | + get(ofDeviceId). | ||
42 | + getSession(). | ||
43 | + getConfig(type); | ||
44 | + } catch (IOException e) { | ||
45 | + log.error("Configuration could not be retrieved {}", | ||
46 | + e.getStackTrace().toString()); | ||
47 | + } | ||
48 | + return UNABLE_TO_READ_CONFIG; | ||
49 | + } | ||
50 | + | ||
51 | +} |
... | @@ -52,6 +52,12 @@ | ... | @@ -52,6 +52,12 @@ |
52 | impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> | 52 | impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> |
53 | <behaviour api="org.onosproject.net.behaviour.ControllerConfig" | 53 | <behaviour api="org.onosproject.net.behaviour.ControllerConfig" |
54 | impl="org.onosproject.driver.netconf.NetconfControllerConfig"/> | 54 | impl="org.onosproject.driver.netconf.NetconfControllerConfig"/> |
55 | + <behaviour api="org.onosproject.net.behaviour.ConfigGetter" | ||
56 | + impl="org.onosproject.driver.netconf.NetconfConfigGetter"/> | ||
57 | + </driver> | ||
58 | + <driver name="netconf" extends="default"> | ||
59 | + <behaviour api="org.onosproject.net.behaviour.ConfigGetter" | ||
60 | + impl="org.onosproject.driver.netconf.NetconfConfigGetter"/> | ||
55 | </driver> | 61 | </driver> |
56 | <driver name="ovs-corsa" extends="ovs" | 62 | <driver name="ovs-corsa" extends="ovs" |
57 | manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0"> | 63 | manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0"> | ... | ... |
-
Please register or login to post a comment