Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * * Copyright 2016 Open Networking Laboratory |
| 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 | |
| 21 | import com.google.common.collect.Lists; |
| 22 | import org.apache.commons.configuration.HierarchicalConfiguration; |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 23 | import org.onosproject.drivers.utilities.XmlConfigParser; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 24 | import org.onosproject.net.AnnotationKeys; |
| 25 | import org.onosproject.net.CltSignalType; |
| 26 | import org.onosproject.net.DefaultAnnotations; |
| 27 | import org.onosproject.net.DeviceId; |
| 28 | import org.onosproject.net.PortNumber; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 29 | import org.onosproject.net.behaviour.PortDiscovery; |
| 30 | import org.onosproject.net.device.OduCltPortDescription; |
| 31 | import org.onosproject.net.device.PortDescription; |
| 32 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 33 | import org.onosproject.net.driver.DriverHandler; |
| 34 | import org.onosproject.protocol.rest.RestSBController; |
| 35 | |
| 36 | import java.util.ArrayList; |
| 37 | import java.util.List; |
| 38 | |
| 39 | import static com.google.common.base.Preconditions.checkNotNull; |
| 40 | |
| 41 | /** |
| 42 | * Discovers the ports from a Ciena WaveServer Rest device. |
| 43 | */ |
| 44 | public class PortDiscoveryCienaWaveserverImpl extends AbstractHandlerBehaviour |
| 45 | implements PortDiscovery { |
| 46 | |
| 47 | private static final String SPEED = "speed"; |
| 48 | private static final String GBPS = "Gbps"; |
| 49 | private static final String PORT_ID = "port-id"; |
| 50 | private static final String XML = "xml"; |
| 51 | private static final String ENABLED = "enabled"; |
| 52 | private static final String EMPTY_STRING = ""; |
| 53 | private static final String NAME = "name"; |
| 54 | private static final String ADMIN_STATE = "admin-state"; |
| 55 | |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 56 | private static final ArrayList<String> LINESIDE_PORT_ID = Lists.newArrayList( |
| 57 | "4", "48"); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 58 | |
| 59 | private static final String GENERAL_PORT_REQUEST = |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 60 | "ws-ports?config=true&format=xml&depth=unbounded"; |
| 61 | private static final String SPECIFIC_PORT_PATH = "ws-ptps/ptp/"; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 62 | private static final String SPECIFIC_PORT_CONFIG = |
| 63 | "/ptp-config?config=true&format=xml&depth=unbounded"; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 64 | //HTTP strings |
| 65 | // private static final String GENERAL_PORT_REQUEST = |
| 66 | // "/yang-api/datastore/ws-ports?config=true&format=xml&depth=unbounded"; |
| 67 | // private static final String SPECIFIC_PORT_PATH = "/yang-api/datastore/ws-ptps/ptp/"; |
| 68 | // private static final String SPECIFIC_PORT_CONFIG = |
| 69 | // "/ptp-config?config=true&format=xml&depth=unbounded"; |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 70 | |
| 71 | |
| 72 | @Override |
| 73 | public List<PortDescription> getPorts() { |
| 74 | List<PortDescription> ports = Lists.newArrayList(); |
| 75 | DriverHandler handler = handler(); |
| 76 | RestSBController controller = checkNotNull(handler.get(RestSBController.class)); |
| 77 | DeviceId deviceId = handler.data().deviceId(); |
| 78 | |
| 79 | |
| 80 | HierarchicalConfiguration config = XmlConfigParser. |
| 81 | loadXml(controller.get(deviceId, GENERAL_PORT_REQUEST, XML)); |
| 82 | List<HierarchicalConfiguration> portsConfig = |
| 83 | XmlConfigParser.parseWaveServerCienaPorts(config); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 84 | portsConfig.stream().forEach(sub -> { |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 85 | String portId = sub.getString(PORT_ID); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 86 | String name = sub.getString(NAME); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 87 | if (LINESIDE_PORT_ID.contains(portId)) { |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 88 | String txName = name + " Tx"; |
| 89 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() |
| 90 | .set(AnnotationKeys.PORT_NAME, txName); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 91 | String wsportInfoRequest = SPECIFIC_PORT_PATH + portId + |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 92 | SPECIFIC_PORT_CONFIG; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 93 | ports.add(XmlConfigParser.parseWaveServerCienaOchPorts( |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 94 | sub.getLong(PORT_ID), |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 95 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
| 96 | .replace(" ", EMPTY_STRING))), |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 97 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 98 | annotations.build())); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 99 | //adding corresponding opposite side port |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 100 | String rxName = name.replace(".1", ".2") + " Rx"; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 101 | ports.add(XmlConfigParser.parseWaveServerCienaOchPorts( |
| 102 | sub.getLong(PORT_ID) + 1, |
| 103 | toGbps(Long.parseLong(sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
| 104 | .replace(" ", EMPTY_STRING))), |
| 105 | XmlConfigParser.loadXml(controller.get(deviceId, wsportInfoRequest, XML)), |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 106 | annotations.set(AnnotationKeys.PORT_NAME, rxName) |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 107 | .build())); |
| 108 | } else if (!portId.equals("5") && !portId.equals("49")) { |
Andrea Campanella | 3afcfd1 | 2016-02-26 11:05:57 -0800 | [diff] [blame] | 109 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() |
| 110 | .set(AnnotationKeys.PORT_NAME, name); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 111 | //FIXME change when all optical types have two way information methods, see jira tickets |
| 112 | final int speed100GbpsinMbps = 100000; |
| 113 | CltSignalType cltType = toGbps(Long.parseLong( |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 114 | sub.getString(SPEED).replace(GBPS, EMPTY_STRING) |
| 115 | .replace(" ", EMPTY_STRING))) == speed100GbpsinMbps ? |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 116 | CltSignalType.CLT_100GBE : null; |
| 117 | ports.add(new OduCltPortDescription(PortNumber.portNumber(sub.getLong(PORT_ID)), |
| 118 | sub.getString(ADMIN_STATE).equals(ENABLED), |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 119 | cltType, annotations.build())); |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 120 | } |
| 121 | }); |
| 122 | return ports; |
| 123 | } |
| 124 | |
| 125 | //FIXME remove when all optical types have two way information methods, see jira tickets |
| 126 | private long toGbps(long speed) { |
| 127 | return speed * 1000; |
| 128 | } |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 129 | |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 130 | } |
| 131 | |