Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 3 | * * Copyright 2016-present Open Networking Laboratory |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 4 | * * |
| 5 | * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * * you may not use this file except in compliance with the License. |
| 7 | * * You may obtain a copy of the License at |
| 8 | * * |
| 9 | * * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * * |
| 11 | * * Unless required by applicable law or agreed to in writing, software |
| 12 | * * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * * See the License for the specific language governing permissions and |
| 15 | * * limitations under the License. |
| 16 | * |
| 17 | */ |
| 18 | |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 19 | package org.onosproject.drivers.ciena; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 20 | |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableList; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 22 | import com.google.common.collect.Lists; |
| 23 | import org.apache.commons.configuration.HierarchicalConfiguration; |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 24 | import org.onosproject.drivers.utilities.XmlConfigParser; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 25 | import org.onosproject.net.AnnotationKeys; |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 26 | import org.onosproject.net.ChannelSpacing; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 27 | import org.onosproject.net.CltSignalType; |
| 28 | import org.onosproject.net.DefaultAnnotations; |
| 29 | import org.onosproject.net.DeviceId; |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 30 | import org.onosproject.net.GridType; |
| 31 | import org.onosproject.net.OchSignal; |
| 32 | import org.onosproject.net.OduSignalType; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 33 | import org.onosproject.net.PortNumber; |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 34 | import org.onosproject.net.SparseAnnotations; |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 35 | import org.onosproject.net.device.DeviceDescription; |
| 36 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 37 | import org.onosproject.net.device.PortDescription; |
| 38 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 39 | import org.onosproject.net.driver.DriverHandler; |
| 40 | import org.onosproject.protocol.rest.RestSBController; |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 41 | import org.slf4j.Logger; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 42 | |
| 43 | import java.util.ArrayList; |
| 44 | import java.util.List; |
| 45 | |
| 46 | import static com.google.common.base.Preconditions.checkNotNull; |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 47 | import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 48 | import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 49 | import static org.slf4j.LoggerFactory.getLogger; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Discovers the ports from a Ciena WaveServer Rest device. |
| 53 | */ |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 54 | public class CienaWaveserverDeviceDescription extends AbstractHandlerBehaviour |
| 55 | implements DeviceDescriptionDiscovery { |
| 56 | |
| 57 | private final Logger log = getLogger(getClass()); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 58 | |
| 59 | private static final String SPEED = "speed"; |
| 60 | private static final String GBPS = "Gbps"; |
| 61 | private static final String PORT_ID = "port-id"; |
| 62 | private static final String XML = "xml"; |
| 63 | private static final String ENABLED = "enabled"; |
| 64 | private static final String EMPTY_STRING = ""; |
| 65 | private static final String NAME = "name"; |
| 66 | private static final String ADMIN_STATE = "admin-state"; |
| 67 | |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 68 | private static final ArrayList<String> LINESIDE_PORT_ID = Lists.newArrayList( |
| 69 | "4", "48"); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 70 | |
| 71 | private static final String GENERAL_PORT_REQUEST = |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 72 | "ws-ports?config=true&format=xml&depth=unbounded"; |
| 73 | private static final String SPECIFIC_PORT_PATH = "ws-ptps/ptp/"; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 74 | private static final String SPECIFIC_PORT_CONFIG = |
| 75 | "/ptp-config?config=true&format=xml&depth=unbounded"; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 76 | //HTTP strings |
| 77 | // private static final String GENERAL_PORT_REQUEST = |
| 78 | // "/yang-api/datastore/ws-ports?config=true&format=xml&depth=unbounded"; |
| 79 | // private static final String SPECIFIC_PORT_PATH = "/yang-api/datastore/ws-ptps/ptp/"; |
| 80 | // private static final String SPECIFIC_PORT_CONFIG = |
| 81 | // "/ptp-config?config=true&format=xml&depth=unbounded"; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 82 | |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 83 | @Override |
| 84 | public DeviceDescription discoverDeviceDetails() { |
| 85 | log.info("No description to be added for device"); |
| 86 | //TODO to be implemented if needed. |
| 87 | return null; |
| 88 | } |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 89 | |
| 90 | @Override |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 91 | public List<PortDescription> discoverPortDetails() { |
| 92 | return getPorts(); |
| 93 | } |
| 94 | |
| 95 | private List<PortDescription> getPorts() { |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 96 | List<PortDescription> ports = Lists.newArrayList(); |
| 97 | DriverHandler handler = handler(); |
| 98 | RestSBController controller = checkNotNull(handler.get(RestSBController.class)); |
| 99 | DeviceId deviceId = handler.data().deviceId(); |
| 100 | |
| 101 | |
| 102 | HierarchicalConfiguration config = XmlConfigParser. |
| 103 | loadXml(controller.get(deviceId, GENERAL_PORT_REQUEST, XML)); |
| 104 | List<HierarchicalConfiguration> portsConfig = |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 105 | parseWaveServerCienaPorts(config); |
Sho SHIMIZU | a09e1bb | 2016-08-01 14:25:25 -0700 | [diff] [blame^] | 106 | portsConfig.forEach(sub -> { |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 107 | String portId = sub.getString(PORT_ID); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 108 | String name = sub.getString(NAME); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 109 | if (LINESIDE_PORT_ID.contains(portId)) { |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 110 | String txName = name + " Tx"; |
| 111 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() |
| 112 | .set(AnnotationKeys.PORT_NAME, txName); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 113 | String wsportInfoRequest = SPECIFIC_PORT_PATH + portId + |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 114 | SPECIFIC_PORT_CONFIG; |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 115 | ports.add(parseWaveServerCienaOchPorts( |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 116 | sub.getLong(PORT_ID), |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 117 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
| 118 | .replace(" ", EMPTY_STRING))), |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 119 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 120 | annotations.build())); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 121 | //adding corresponding opposite side port |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 122 | String rxName = name.replace(".1", ".2") + " Rx"; |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 123 | ports.add(parseWaveServerCienaOchPorts( |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 124 | sub.getLong(PORT_ID) + 1, |
| 125 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
| 126 | .replace(" ", EMPTY_STRING))), |
| 127 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 128 | annotations.set(AnnotationKeys.PORT_NAME, rxName) |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 129 | .build())); |
| 130 | } else if (!portId.equals("5") && !portId.equals("49")) { |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 131 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() |
| 132 | .set(AnnotationKeys.PORT_NAME, name); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 133 | //FIXME change when all optical types have two way information methods, see jira tickets |
| 134 | final int speed100GbpsinMbps = 100000; |
| 135 | CltSignalType cltType = toGbps(Long.parseLong( |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 136 | sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
| 137 | .replace(" ", EMPTY_STRING))) == speed100GbpsinMbps ? |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 138 | CltSignalType.CLT_100GBE : null; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 139 | ports.add(oduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 140 | sub.getString(ADMIN_STATE).equals(ENABLED), |
| 141 | cltType, annotations.build())); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 142 | } |
| 143 | }); |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 144 | return ImmutableList.copyOf(ports); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 145 | } |
| 146 | |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 147 | public static List<HierarchicalConfiguration> parseWaveServerCienaPorts(HierarchicalConfiguration cfg) { |
| 148 | return cfg.configurationsAt("ws-ports.port-interface"); |
| 149 | } |
| 150 | |
| 151 | public static PortDescription parseWaveServerCienaOchPorts(long portNumber, long oduPortSpeed, |
| 152 | HierarchicalConfiguration config, |
| 153 | SparseAnnotations annotations) { |
| 154 | final List<String> tunableType = Lists.newArrayList("Performance-Optimized", "Accelerated"); |
| 155 | final String transmitterPath = "ptp-config.transmitter-state"; |
| 156 | final String tunablePath = "ptp-config.adv-config.tx-tuning-mode"; |
| 157 | final String gridTypePath = "ptp-config.adv-config.wl-spacing"; |
| 158 | final String frequencyPath = "ptp-config.adv-config.frequency"; |
| 159 | |
| 160 | boolean isEnabled = config.getString(transmitterPath).equals("enabled"); |
| 161 | boolean isTunable = tunableType.contains(config.getString(tunablePath)); |
| 162 | |
| 163 | //FIXME change when all optical types have two way information methods, see jira tickets |
| 164 | final int speed100GbpsinMbps = 100000; |
| 165 | OduSignalType oduSignalType = oduPortSpeed == speed100GbpsinMbps ? OduSignalType.ODU4 : null; |
| 166 | GridType gridType = config.getString(gridTypePath).equals("FlexGrid") ? GridType.FLEX : null; |
| 167 | ChannelSpacing chSpacing = gridType == GridType.FLEX ? ChannelSpacing.CHL_6P25GHZ : null; |
| 168 | |
| 169 | //Working in Ghz //(Nominal central frequency - 193.1)/channelSpacing = spacingMultiplier |
| 170 | final int baseFrequency = 193100; |
| 171 | int spacingMult = (int) (toGbps((Integer.parseInt(config.getString(frequencyPath)) - |
| 172 | baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ? |
| 173 | |
| 174 | return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, oduSignalType, isTunable, |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame] | 175 | new OchSignal(gridType, chSpacing, spacingMult, 1), annotations); |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 178 | //FIXME remove when all optical types have two way information methods, see jira tickets |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 179 | private static long toGbps(long speed) { |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 180 | return speed * 1000; |
| 181 | } |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 182 | |
HIGUCHI Yuta | 9605c78 | 2016-05-16 14:34:05 -0700 | [diff] [blame] | 183 | private static long toGbpsFromHz(long speed) { |
| 184 | return speed / 1000; |
| 185 | } |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 186 | } |
| 187 | |