Committed by
Gerrit Code Review
Adding fujitsu t200 driver, reads OCH and ODUclt port descriptions from netconf.…
… Does not work with the simulator! Change-Id: I91e624eb747870b7a74d4d4c30e1748b637f7411
Showing
9 changed files
with
205 additions
and
12 deletions
... | @@ -49,4 +49,4 @@ public class DevicePortGetterCommand extends AbstractShellCommand { | ... | @@ -49,4 +49,4 @@ public class DevicePortGetterCommand extends AbstractShellCommand { |
49 | print(portConfig.getPorts().toString()); | 49 | print(portConfig.getPorts().toString()); |
50 | } | 50 | } |
51 | 51 | ||
52 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
52 | +} | ... | ... |
drivers/fujitsu/features.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
2 | + | ||
3 | +<!-- | ||
4 | + ~ Copyright 2016 Open Networking Laboratory | ||
5 | + ~ | ||
6 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
7 | + ~ you may not use this file except in compliance with the License. | ||
8 | + ~ You may obtain a copy of the License at | ||
9 | + ~ | ||
10 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
11 | + ~ | ||
12 | + ~ Unless required by applicable law or agreed to in writing, software | ||
13 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
14 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
15 | + ~ See the License for the specific language governing permissions and | ||
16 | + ~ limitations under the License. | ||
17 | + --> | ||
18 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
19 | + <feature name="${project.artifactId}" version="${project.version}" | ||
20 | + description="${project.description}"> | ||
21 | + <feature>onos-api</feature> | ||
22 | + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle> | ||
23 | + | ||
24 | + <bundle>mvn:${project.groupId}/onos-drivers-utilities/${project.version}</bundle> | ||
25 | + | ||
26 | + <bundle>mvn:${project.groupId}/onos-netconf-api/${project.version}</bundle> | ||
27 | + </feature> | ||
28 | +</features> |
... | @@ -26,6 +26,18 @@ | ... | @@ -26,6 +26,18 @@ |
26 | <modelVersion>4.0.0</modelVersion> | 26 | <modelVersion>4.0.0</modelVersion> |
27 | 27 | ||
28 | <description>Fujitsu device drivers</description> | 28 | <description>Fujitsu device drivers</description> |
29 | + <dependencies> | ||
30 | + <dependency> | ||
31 | + <groupId>org.onosproject</groupId> | ||
32 | + <artifactId>onos-netconf-api</artifactId> | ||
33 | + <version>${project.version}</version> | ||
34 | + </dependency> | ||
35 | + <dependency> | ||
36 | + <groupId>org.onosproject</groupId> | ||
37 | + <artifactId>onos-drivers-utilities</artifactId> | ||
38 | + <version>${project.version}</version> | ||
39 | + </dependency> | ||
40 | + </dependencies> | ||
29 | 41 | ||
30 | <artifactId>onos-drivers-fujitsu</artifactId> | 42 | <artifactId>onos-drivers-fujitsu</artifactId> |
31 | <packaging>bundle</packaging> | 43 | <packaging>bundle</packaging> | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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.utilities.XmlConfigParser; | ||
20 | +import org.onosproject.net.behaviour.PortDiscovery; | ||
21 | +import org.onosproject.net.device.PortDescription; | ||
22 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
23 | +import org.onosproject.netconf.NetconfController; | ||
24 | +import org.onosproject.netconf.NetconfException; | ||
25 | +import org.onosproject.netconf.NetconfSession; | ||
26 | +import org.slf4j.Logger; | ||
27 | + | ||
28 | +import java.io.ByteArrayInputStream; | ||
29 | +import java.io.IOException; | ||
30 | +import java.util.List; | ||
31 | + | ||
32 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
33 | +import static org.slf4j.LoggerFactory.getLogger; | ||
34 | + | ||
35 | +/** | ||
36 | + * Retrieves the ports from a Fujitsu T100 device via netconf. | ||
37 | + */ | ||
38 | +public class PortGetterFujitsuImpl extends AbstractHandlerBehaviour | ||
39 | + implements PortDiscovery { | ||
40 | + | ||
41 | + private final Logger log = getLogger(getClass()); | ||
42 | + | ||
43 | + @Override | ||
44 | + public List<PortDescription> getPorts() { | ||
45 | + NetconfController controller = checkNotNull(handler().get(NetconfController.class)); | ||
46 | + NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession(); | ||
47 | + String reply; | ||
48 | + try { | ||
49 | + reply = session.get(requestBuilder()); | ||
50 | + } catch (IOException e) { | ||
51 | + throw new RuntimeException(new NetconfException("Failed to retrieve configuration.", e)); | ||
52 | + } | ||
53 | + List<PortDescription> descriptions = XmlConfigParser. | ||
54 | + parseFujitsuT100Ports(XmlConfigParser. | ||
55 | + loadXml(new ByteArrayInputStream(reply.getBytes()))); | ||
56 | + return descriptions; | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * Builds a request crafted to get the configuration required to create port | ||
61 | + * descriptions for the device. | ||
62 | + * @return The request string. | ||
63 | + */ | ||
64 | + private String requestBuilder() { | ||
65 | + StringBuilder rpc = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); | ||
66 | + //Message ID is injected later. | ||
67 | + rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"); | ||
68 | + rpc.append("<get>"); | ||
69 | + rpc.append("<filter type=\"subtree\">"); | ||
70 | + rpc.append("<interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">"); | ||
71 | + rpc.append("</interfaces>"); | ||
72 | + rpc.append("</filter>"); | ||
73 | + rpc.append("</get>"); | ||
74 | + rpc.append("</rpc>"); | ||
75 | + return rpc.toString(); | ||
76 | + } | ||
77 | +} |
... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /** | 17 | /** |
18 | - * Package for Ciena device drivers. | 18 | + * Package for fujitsu device drivers. |
19 | */ | 19 | */ |
20 | package org.onosproject.drivers.fujitsu; | 20 | package org.onosproject.drivers.fujitsu; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
15 | ~ limitations under the License. | 15 | ~ limitations under the License. |
16 | --> | 16 | --> |
17 | <drivers> | 17 | <drivers> |
18 | - <driver> | 18 | + <driver name="fujitsu-netconf" manufacturer="Fujitsu" hwVersion="T100" swVersion="01-01-X"> |
19 | - </driver> | 19 | + <behaviour api="org.onosproject.net.behaviour.PortDiscovery" |
20 | + impl="org.onosproject.drivers.fujitsu.PortGetterFujitsuImpl"/> | ||
21 | + </driver> | ||
20 | </drivers> | 22 | </drivers> |
21 | 23 | ... | ... |
... | @@ -22,7 +22,10 @@ import org.apache.commons.configuration.HierarchicalConfiguration; | ... | @@ -22,7 +22,10 @@ import org.apache.commons.configuration.HierarchicalConfiguration; |
22 | import org.apache.commons.configuration.XMLConfiguration; | 22 | import org.apache.commons.configuration.XMLConfiguration; |
23 | import org.apache.commons.configuration.tree.ConfigurationNode; | 23 | import org.apache.commons.configuration.tree.ConfigurationNode; |
24 | import org.onlab.packet.IpAddress; | 24 | import org.onlab.packet.IpAddress; |
25 | +import org.onosproject.net.AnnotationKeys; | ||
25 | import org.onosproject.net.ChannelSpacing; | 26 | import org.onosproject.net.ChannelSpacing; |
27 | +import org.onosproject.net.CltSignalType; | ||
28 | +import org.onosproject.net.DefaultAnnotations; | ||
26 | import org.onosproject.net.GridType; | 29 | import org.onosproject.net.GridType; |
27 | import org.onosproject.net.OchSignal; | 30 | import org.onosproject.net.OchSignal; |
28 | import org.onosproject.net.OduSignalType; | 31 | import org.onosproject.net.OduSignalType; |
... | @@ -30,6 +33,7 @@ import org.onosproject.net.PortNumber; | ... | @@ -30,6 +33,7 @@ import org.onosproject.net.PortNumber; |
30 | import org.onosproject.net.SparseAnnotations; | 33 | import org.onosproject.net.SparseAnnotations; |
31 | import org.onosproject.net.behaviour.ControllerInfo; | 34 | import org.onosproject.net.behaviour.ControllerInfo; |
32 | import org.onosproject.net.device.OchPortDescription; | 35 | import org.onosproject.net.device.OchPortDescription; |
36 | +import org.onosproject.net.device.OduCltPortDescription; | ||
33 | import org.onosproject.net.device.PortDescription; | 37 | import org.onosproject.net.device.PortDescription; |
34 | import org.slf4j.Logger; | 38 | import org.slf4j.Logger; |
35 | import org.slf4j.LoggerFactory; | 39 | import org.slf4j.LoggerFactory; |
... | @@ -38,6 +42,8 @@ import java.io.InputStream; | ... | @@ -38,6 +42,8 @@ import java.io.InputStream; |
38 | import java.io.StringWriter; | 42 | import java.io.StringWriter; |
39 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
40 | import java.util.List; | 44 | import java.util.List; |
45 | +import java.util.concurrent.atomic.AtomicInteger; | ||
46 | + | ||
41 | 47 | ||
42 | /** | 48 | /** |
43 | * Parser for Netconf XML configurations and replys. | 49 | * Parser for Netconf XML configurations and replys. |
... | @@ -76,7 +82,56 @@ public final class XmlConfigParser { | ... | @@ -76,7 +82,56 @@ public final class XmlConfigParser { |
76 | return controllers; | 82 | return controllers; |
77 | } | 83 | } |
78 | 84 | ||
79 | - public static String parseSwitchId(HierarchicalConfiguration cfg) { | 85 | + /** |
86 | + * Parses a configuration and returns a set of ports for the fujitsu T100. | ||
87 | + * @param cfg a hierarchical configuration | ||
88 | + * @return a list of port descriptions | ||
89 | + */ | ||
90 | + public static List<PortDescription> parseFujitsuT100Ports(HierarchicalConfiguration cfg) { | ||
91 | + AtomicInteger counter = new AtomicInteger(1); | ||
92 | + List<PortDescription> portDescriptions = Lists.newArrayList(); | ||
93 | + List<HierarchicalConfiguration> subtrees = | ||
94 | + cfg.configurationsAt("data.interfaces.interface"); | ||
95 | + for (HierarchicalConfiguration portConfig : subtrees) { | ||
96 | + if (!portConfig.getString("name").contains("LCN") && | ||
97 | + !portConfig.getString("name").contains("LMP") && | ||
98 | + portConfig.getString("type").equals("ianaift:ethernetCsmacd")) { | ||
99 | + portDescriptions.add(parseT100OduPort(portConfig, counter.getAndIncrement())); | ||
100 | + } else if (portConfig.getString("type").equals("ianaift:otnOtu")) { | ||
101 | + portDescriptions.add(parseT100OchPort(portConfig, counter.getAndIncrement())); | ||
102 | + } | ||
103 | + } | ||
104 | + return portDescriptions; | ||
105 | + } | ||
106 | + | ||
107 | + private static OchPortDescription parseT100OchPort(HierarchicalConfiguration cfg, long count) { | ||
108 | + PortNumber portNumber = PortNumber.portNumber(count); | ||
109 | + HierarchicalConfiguration otuConfig = cfg.configurationAt("otu"); | ||
110 | + boolean enabled = otuConfig.getString("administrative-state").equals("up"); | ||
111 | + OduSignalType signalType = otuConfig.getString("rate").equals("OTU4") ? OduSignalType.ODU4 : null; | ||
112 | + //Unsure how to retreive, outside knowledge it is tunable. | ||
113 | + boolean isTunable = true; | ||
114 | + OchSignal lambda = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4); | ||
115 | + DefaultAnnotations annotations = DefaultAnnotations.builder(). | ||
116 | + set(AnnotationKeys.PORT_NAME, cfg.getString("name")). | ||
117 | + build(); | ||
118 | + return new OchPortDescription(portNumber, enabled, signalType, isTunable, lambda, annotations); | ||
119 | + } | ||
120 | + | ||
121 | + private static OduCltPortDescription parseT100OduPort(HierarchicalConfiguration cfg, long count) { | ||
122 | + PortNumber portNumber = PortNumber.portNumber(count); | ||
123 | + HierarchicalConfiguration ethernetConfig = cfg.configurationAt("ethernet"); | ||
124 | + boolean enabled = ethernetConfig.getString("administrative-state").equals("up"); | ||
125 | + //Rate is in kbps | ||
126 | + CltSignalType signalType = ethernetConfig.getString("rate").equals("100000000") ? | ||
127 | + CltSignalType.CLT_100GBE : null; | ||
128 | + DefaultAnnotations annotations = DefaultAnnotations.builder(). | ||
129 | + set(AnnotationKeys.PORT_NAME, cfg.getString("name")). | ||
130 | + build(); | ||
131 | + return new OduCltPortDescription(portNumber, enabled, signalType, annotations); | ||
132 | + } | ||
133 | + | ||
134 | + protected static String parseSwitchId(HierarchicalConfiguration cfg) { | ||
80 | HierarchicalConfiguration field = | 135 | HierarchicalConfiguration field = |
81 | cfg.configurationAt("data.capable-switch." + | 136 | cfg.configurationAt("data.capable-switch." + |
82 | "logical-switches." + | 137 | "logical-switches." + | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | ~ limitations under the License. | 15 | ~ limitations under the License. |
16 | --> | 16 | --> |
17 | <app name="org.onosproject.netconf" origin="ON.Lab" version="${project.version}" | 17 | <app name="org.onosproject.netconf" origin="ON.Lab" version="${project.version}" |
18 | - category="default" url="http://onosproject.org" apps="org.onosproject.drivers.netconf" | 18 | + category="default" url="http://onosproject.org" |
19 | featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | 19 | featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" |
20 | features="${project.artifactId}"> | 20 | features="${project.artifactId}"> |
21 | <description>${project.description}</description> | 21 | <description>${project.description}</description> | ... | ... |
... | @@ -31,6 +31,7 @@ import org.onosproject.net.Device; | ... | @@ -31,6 +31,7 @@ import org.onosproject.net.Device; |
31 | import org.onosproject.net.DeviceId; | 31 | import org.onosproject.net.DeviceId; |
32 | import org.onosproject.net.MastershipRole; | 32 | import org.onosproject.net.MastershipRole; |
33 | import org.onosproject.net.SparseAnnotations; | 33 | import org.onosproject.net.SparseAnnotations; |
34 | +import org.onosproject.net.behaviour.PortDiscovery; | ||
34 | import org.onosproject.net.config.ConfigFactory; | 35 | import org.onosproject.net.config.ConfigFactory; |
35 | import org.onosproject.net.config.NetworkConfigEvent; | 36 | import org.onosproject.net.config.NetworkConfigEvent; |
36 | import org.onosproject.net.config.NetworkConfigListener; | 37 | import org.onosproject.net.config.NetworkConfigListener; |
... | @@ -40,6 +41,8 @@ import org.onosproject.net.device.DeviceDescription; | ... | @@ -40,6 +41,8 @@ import org.onosproject.net.device.DeviceDescription; |
40 | import org.onosproject.net.device.DeviceProvider; | 41 | import org.onosproject.net.device.DeviceProvider; |
41 | import org.onosproject.net.device.DeviceProviderRegistry; | 42 | import org.onosproject.net.device.DeviceProviderRegistry; |
42 | import org.onosproject.net.device.DeviceProviderService; | 43 | import org.onosproject.net.device.DeviceProviderService; |
44 | +import org.onosproject.net.device.DeviceService; | ||
45 | +import org.onosproject.net.driver.DriverService; | ||
43 | import org.onosproject.net.provider.AbstractProvider; | 46 | import org.onosproject.net.provider.AbstractProvider; |
44 | import org.onosproject.net.provider.ProviderId; | 47 | import org.onosproject.net.provider.ProviderId; |
45 | import org.onosproject.netconf.NetconfController; | 48 | import org.onosproject.netconf.NetconfController; |
... | @@ -74,6 +77,12 @@ public class NetconfDeviceProvider extends AbstractProvider | ... | @@ -74,6 +77,12 @@ public class NetconfDeviceProvider extends AbstractProvider |
74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
75 | protected CoreService coreService; | 78 | protected CoreService coreService; |
76 | 79 | ||
80 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
81 | + protected DriverService driverService; | ||
82 | + | ||
83 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
84 | + protected DeviceService deviceService; | ||
85 | + | ||
77 | private static final String APP_NAME = "org.onosproject.netconf"; | 86 | private static final String APP_NAME = "org.onosproject.netconf"; |
78 | private static final String SCHEME_NAME = "netconf"; | 87 | private static final String SCHEME_NAME = "netconf"; |
79 | private static final String DEVICE_PROVIDER_PACKAGE = "org.onosproject.netconf.provider.device"; | 88 | private static final String DEVICE_PROVIDER_PACKAGE = "org.onosproject.netconf.provider.device"; |
... | @@ -166,7 +175,6 @@ public class NetconfDeviceProvider extends AbstractProvider | ... | @@ -166,7 +175,6 @@ public class NetconfDeviceProvider extends AbstractProvider |
166 | cid, | 175 | cid, |
167 | annotations); | 176 | annotations); |
168 | providerService.deviceConnected(deviceId, deviceDescription); | 177 | providerService.deviceConnected(deviceId, deviceDescription); |
169 | - | ||
170 | } | 178 | } |
171 | 179 | ||
172 | @Override | 180 | @Override |
... | @@ -185,11 +193,22 @@ public class NetconfDeviceProvider extends AbstractProvider | ... | @@ -185,11 +193,22 @@ public class NetconfDeviceProvider extends AbstractProvider |
185 | cfg.getDevicesAddresses().stream() | 193 | cfg.getDevicesAddresses().stream() |
186 | .forEach(addr -> { | 194 | .forEach(addr -> { |
187 | try { | 195 | try { |
188 | - controller.connectDevice( | 196 | + NetconfDeviceInfo netconf = new NetconfDeviceInfo(addr.name(), |
189 | - new NetconfDeviceInfo(addr.name(), | 197 | + addr.password(), |
190 | - addr.password(), | 198 | + addr.ip(), |
191 | - addr.ip(), | 199 | + addr.port()); |
192 | - addr.port())); | 200 | + controller.connectDevice(netconf); |
201 | + Device device = deviceService.getDevice(netconf.getDeviceId()); | ||
202 | + if (device.is(PortDiscovery.class)) { | ||
203 | + PortDiscovery portConfig = device.as(PortDiscovery.class); | ||
204 | + if (portConfig != null) { | ||
205 | + providerService.updatePorts(netconf.getDeviceId(), | ||
206 | + portConfig.getPorts()); | ||
207 | + } | ||
208 | + } else { | ||
209 | + log.warn("No portGetter behaviour for device {}", netconf.getDeviceId()); | ||
210 | + } | ||
211 | + | ||
193 | } catch (IOException e) { | 212 | } catch (IOException e) { |
194 | throw new RuntimeException( | 213 | throw new RuntimeException( |
195 | new NetconfException( | 214 | new NetconfException( | ... | ... |
-
Please register or login to post a comment