Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.of.device.impl; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 17 | |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 18 | import com.google.common.base.Strings; |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.Lists; |
| 21 | import com.google.common.collect.Maps; |
| 22 | import com.google.common.collect.Sets; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Activate; |
| 24 | import org.apache.felix.scr.annotations.Component; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Modified; |
| 27 | import org.apache.felix.scr.annotations.Property; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 28 | import org.apache.felix.scr.annotations.Reference; |
| 29 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 30 | import org.onlab.packet.ChassisId; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 31 | import org.onlab.util.Frequency; |
| 32 | import org.onlab.util.Spectrum; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 33 | import org.onosproject.cfg.ComponentConfigService; |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 34 | import org.onosproject.net.AnnotationKeys; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 35 | import org.onosproject.net.ChannelSpacing; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 36 | import org.onosproject.net.CltSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 37 | import org.onosproject.net.DefaultAnnotations; |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 38 | import org.onosproject.net.DefaultAnnotations.Builder; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 39 | import org.onosproject.net.Device; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 40 | import org.onosproject.net.DeviceId; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 41 | import org.onosproject.net.GridType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 42 | import org.onosproject.net.MastershipRole; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 43 | import org.onosproject.net.OchSignal; |
| 44 | import org.onosproject.net.OduSignalType; |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 45 | import org.onosproject.net.OtuSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 46 | import org.onosproject.net.Port; |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 47 | import org.onosproject.net.Port.Type; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 48 | import org.onosproject.net.PortNumber; |
| 49 | import org.onosproject.net.SparseAnnotations; |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 50 | import org.onosproject.net.behaviour.LambdaQuery; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 51 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 52 | import org.onosproject.net.device.DefaultPortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 53 | import org.onosproject.net.device.DefaultPortStatistics; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 54 | import org.onosproject.net.device.DeviceDescription; |
| 55 | import org.onosproject.net.device.DeviceProvider; |
| 56 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 57 | import org.onosproject.net.device.DeviceProviderService; |
| 58 | import org.onosproject.net.device.PortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 59 | import org.onosproject.net.device.PortStatistics; |
Victor Silva | ac8dab0 | 2016-11-28 16:33:08 -0300 | [diff] [blame] | 60 | import org.onosproject.net.driver.Driver; |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 61 | import org.onosproject.net.driver.DriverHandler; |
Victor Silva | ac8dab0 | 2016-11-28 16:33:08 -0300 | [diff] [blame] | 62 | import org.onosproject.net.driver.DriverService; |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 63 | import org.onosproject.net.driver.HandlerBehaviour; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 64 | import org.onosproject.net.provider.AbstractProvider; |
| 65 | import org.onosproject.net.provider.ProviderId; |
| 66 | import org.onosproject.openflow.controller.Dpid; |
| 67 | import org.onosproject.openflow.controller.OpenFlowController; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 68 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 69 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 70 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 71 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 72 | import org.onosproject.openflow.controller.PortDescPropertyType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 73 | import org.onosproject.openflow.controller.RoleState; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 74 | import org.osgi.service.component.ComponentContext; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 75 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescProp; |
| 76 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescPropOptical; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 77 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry; |
Laszlo Papp | 5817481 | 2018-01-16 13:29:47 +0000 | [diff] [blame] | 78 | import org.projectfloodlight.openflow.protocol.OFCapabilities; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 79 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 80 | import org.projectfloodlight.openflow.protocol.OFErrorType; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 81 | import org.projectfloodlight.openflow.protocol.OFExpPort; |
| 82 | import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport; |
| 83 | import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry; |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 84 | import org.projectfloodlight.openflow.protocol.OFFactory; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 85 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 86 | import org.projectfloodlight.openflow.protocol.OFObject; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 87 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 88 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 89 | import org.projectfloodlight.openflow.protocol.OFPortDescPropEthernet; |
| 90 | import org.projectfloodlight.openflow.protocol.OFPortDescPropOptical; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 91 | import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 92 | import org.projectfloodlight.openflow.protocol.OFPortFeatures; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 93 | import org.projectfloodlight.openflow.protocol.OFPortMod; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 94 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 95 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass; |
| 96 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType; |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 97 | import org.projectfloodlight.openflow.protocol.OFPortReason; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 98 | import org.projectfloodlight.openflow.protocol.OFPortState; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 99 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 100 | import org.projectfloodlight.openflow.protocol.OFPortStatsPropOptical; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 101 | import org.projectfloodlight.openflow.protocol.OFPortStatsReply; |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 102 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 103 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 104 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 105 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 106 | import org.projectfloodlight.openflow.protocol.OFVersion; |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 107 | import org.projectfloodlight.openflow.protocol.ver14.OFOpticalPortFeaturesSerializerVer14; |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 108 | import org.projectfloodlight.openflow.protocol.ver14.OFPortStatsOpticalFlagsSerializerVer14; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 109 | import org.projectfloodlight.openflow.types.OFPort; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 110 | import org.projectfloodlight.openflow.types.PortSpeed; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 111 | import org.slf4j.Logger; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 112 | |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 113 | import java.util.ArrayList; |
| 114 | import java.util.Collection; |
| 115 | import java.util.Collections; |
| 116 | import java.util.Comparator; |
| 117 | import java.util.Dictionary; |
Jimmy Jin | e9b7a02 | 2016-08-12 16:56:48 -0700 | [diff] [blame] | 118 | import java.util.EnumSet; |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 119 | import java.util.HashMap; |
| 120 | import java.util.HashSet; |
| 121 | import java.util.List; |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 122 | import java.util.Optional; |
Marc De Leenheer | 8aba62f | 2017-04-25 14:33:37 -0700 | [diff] [blame] | 123 | import java.util.Properties; |
| 124 | import java.util.Set; |
| 125 | import java.util.Timer; |
| 126 | |
| 127 | import static com.google.common.base.Preconditions.checkArgument; |
| 128 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 129 | import static org.onlab.util.Tools.get; |
| 130 | import static org.onosproject.net.DeviceId.deviceId; |
| 131 | import static org.onosproject.net.Port.Type.COPPER; |
| 132 | import static org.onosproject.net.Port.Type.FIBER; |
| 133 | import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription; |
| 134 | import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; |
| 135 | import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription; |
| 136 | import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription; |
| 137 | import static org.onosproject.openflow.controller.Dpid.dpid; |
| 138 | import static org.onosproject.openflow.controller.Dpid.uri; |
| 139 | import static org.slf4j.LoggerFactory.getLogger; |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 140 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 141 | /** |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 142 | * Provider which uses an OpenFlow controller to detect network |
tom | e06f855 | 2014-08-26 16:58:42 -0700 | [diff] [blame] | 143 | * infrastructure devices. |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 144 | */ |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 145 | @Component(immediate = true) |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 146 | public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider { |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 147 | |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 148 | private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 149 | |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 150 | // TODO Some duplicate with one defined in OpticalAnnotations |
| 151 | // slice out optical specific handling and consolidate. |
| 152 | /** |
| 153 | * Annotation key for minimum frequency in Hz. |
| 154 | * Value is expected to be an integer. |
| 155 | */ |
| 156 | public static final String AK_MIN_FREQ_HZ = "minFrequency"; |
| 157 | |
| 158 | /** |
| 159 | * Annotation key for maximum frequency in Hz. |
| 160 | * Value is expected be an integer. |
| 161 | */ |
| 162 | public static final String AK_MAX_FREQ_HZ = "maxFrequency"; |
| 163 | |
| 164 | /** |
| 165 | * Annotation key for grid in Hz. |
| 166 | * Value is expected to be an integer. |
| 167 | */ |
| 168 | public static final String AK_GRID_HZ = "grid"; |
| 169 | |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 170 | /** |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 171 | * Annotation key for minimum frequency in Hz. |
| 172 | * Value is expected to be an integer. |
| 173 | */ |
| 174 | public static final String AK_TX_MIN_FREQ_HZ = "txMinFrequency"; |
| 175 | |
| 176 | /** |
| 177 | * Annotation key for maximum frequency in Hz. |
| 178 | * Value is expected be an integer. |
| 179 | */ |
| 180 | public static final String AK_TX_MAX_FREQ_HZ = "txMaxFrequency"; |
| 181 | |
| 182 | /** |
| 183 | * Annotation key for grid in Hz. |
| 184 | * Value is expected to be an integer. |
| 185 | */ |
| 186 | public static final String AK_TX_GRID_HZ = "txGrid"; |
| 187 | |
| 188 | /** |
| 189 | * Annotation key for minimum frequency in Hz. |
| 190 | * Value is expected to be an integer. |
| 191 | */ |
| 192 | public static final String AK_RX_MIN_FREQ_HZ = "rxMinFrequency"; |
| 193 | |
| 194 | /** |
| 195 | * Annotation key for maximum frequency in Hz. |
| 196 | * Value is expected be an integer. |
| 197 | */ |
| 198 | public static final String AK_RX_MAX_FREQ_HZ = "rxMaxFrequency"; |
| 199 | |
| 200 | /** |
| 201 | * Annotation key for grid in Hz. |
| 202 | * Value is expected to be an integer. |
| 203 | */ |
| 204 | public static final String AK_RX_GRID_HZ = "rxGrid"; |
| 205 | |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 206 | /** |
| 207 | * Annotation key for minimum transmit power in dBm*10. |
| 208 | * Value is expected to be an integer. |
| 209 | */ |
| 210 | public static final String AK_TX_PWR_MIN = "txPowerMin"; |
| 211 | |
| 212 | /** |
| 213 | * Annotation key for maximum transmit power in dBm*10. |
| 214 | * Value is expected to be an integer. |
| 215 | */ |
| 216 | public static final String AK_TX_PWR_MAX = "txPowerMax"; |
| 217 | |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 218 | |
| 219 | |
| 220 | // Port Stats annotations |
| 221 | |
| 222 | /** |
| 223 | * Annotation key for transmit frequency in Hz. |
| 224 | * Value is expected be an integer. |
| 225 | */ |
| 226 | public static final String AK_TX_FREQ_HZ = "txFrequency"; |
| 227 | |
| 228 | /** |
| 229 | * Annotation key for transmit offset in Hz. |
| 230 | * Value is expected be an integer. |
| 231 | */ |
| 232 | public static final String AK_TX_OFFSET_HZ = "txOffset"; |
| 233 | |
| 234 | /** |
| 235 | * Annotation key for transmit grid spacing in Hz. |
| 236 | * Value is expected be an integer. |
| 237 | */ |
| 238 | public static final String AK_TX_GRID_SPAN_HZ = "txGridSpan"; |
| 239 | |
| 240 | /** |
| 241 | * Annotation key for receive frequency in Hz. |
| 242 | * Value is expected be an integer. |
| 243 | */ |
| 244 | public static final String AK_RX_FREQ_HZ = "rxFrequency"; |
| 245 | |
| 246 | /** |
| 247 | * Annotation key for receive offset in Hz. |
| 248 | * Value is expected be an integer. |
| 249 | */ |
| 250 | public static final String AK_RX_OFFSET_HZ = "rxOffset"; |
| 251 | |
| 252 | /** |
| 253 | * Annotation key for receive grid spacing in Hz. |
| 254 | * Value is expected be an integer. |
| 255 | */ |
| 256 | public static final String AK_RX_GRID_SPAN_HZ = "rxGridSpan"; |
| 257 | |
| 258 | /** |
| 259 | * Annotation key for transmit power in dBm*10. |
| 260 | * Value is expected to be an integer. |
| 261 | */ |
| 262 | public static final String AK_TX_PWR = "txPower"; |
| 263 | |
| 264 | /** |
| 265 | * Annotation key for receive power feature. |
| 266 | * Value is expected to be "enabled" or "disabled" |
| 267 | */ |
| 268 | public static final String AK_RX_PWR_FEATURE = "rxPwrFeature"; |
| 269 | |
| 270 | /** |
| 271 | * Annotation key for receive power in dBm*10. |
| 272 | * Value is expected to be an integer. |
| 273 | */ |
| 274 | public static final String AK_RX_PWR = "rxPower"; |
| 275 | |
| 276 | /** |
| 277 | * Annotation key for transmit bias feature. |
| 278 | * Value is expected to be "enabled" or "disabled" |
| 279 | */ |
| 280 | public static final String AK_TX_BIAS_FEATURE = "txBiasFeature"; |
| 281 | |
| 282 | /** |
| 283 | * Annotation key for transmit bias current in mA*10. |
| 284 | * Value is expected to be an integer. |
| 285 | */ |
| 286 | public static final String AK_BIAS_CURRENT = "biasCurrent"; |
| 287 | |
| 288 | /** |
| 289 | * Annotation key for transmit temperature feature. |
| 290 | * Value is expected to be "enabled" or "disabled" |
| 291 | */ |
| 292 | public static final String AK_TX_TEMP_FEATURE = "txTempFeature"; |
| 293 | |
| 294 | /** |
| 295 | * Annotation key for transmit laser temperature in C*10. |
| 296 | * Value is expected to be an integer. |
| 297 | */ |
| 298 | public static final String AK_TEMPERATURE = "temperature"; |
| 299 | |
| 300 | |
| 301 | // Common feature annotations |
| 302 | |
| 303 | /** |
| 304 | * Annotation key for transmit tune feature. |
| 305 | * Value is expected to be "enabled" or "disabled" |
| 306 | */ |
| 307 | public static final String AK_TX_TUNE_FEATURE = "txTuneFeature"; |
| 308 | |
| 309 | /** |
| 310 | * Annotation key for receive tune feature. |
| 311 | * Value is expected to be "enabled" or "disabled" |
| 312 | */ |
| 313 | public static final String AK_RX_TUNE_FEATURE = "rxTuneFeature"; |
| 314 | |
| 315 | /** |
| 316 | * Annotation key for transmit power feature. |
| 317 | * Value is expected to be "enabled" or "disabled" |
| 318 | */ |
| 319 | public static final String AK_TX_PWR_FEATURE = "txPwrFeature"; |
| 320 | |
| 321 | |
Charles Chan | 25b7732 | 2015-12-13 01:00:56 -0800 | [diff] [blame] | 322 | //TODO consider renaming KBPS and MBPS (as they are used to convert by division) |
| 323 | private static final long KBPS = 1_000; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 324 | private static final long MBPS = 1_000 * 1_000; |
Rimon Ashkenazy | e320103 | 2016-01-11 14:27:30 +0200 | [diff] [blame] | 325 | private static final Frequency FREQ50 = Frequency.ofGHz(50); |
| 326 | private static final Frequency FREQ191_7 = Frequency.ofGHz(191_700); |
Sho SHIMIZU | 00762ee | 2016-01-05 16:32:24 -0800 | [diff] [blame] | 327 | private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 328 | |
| 329 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 330 | protected DeviceProviderRegistry providerRegistry; |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 331 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 332 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 333 | protected OpenFlowController controller; |
| 334 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 335 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 336 | protected ComponentConfigService cfgService; |
| 337 | |
Victor Silva | ac8dab0 | 2016-11-28 16:33:08 -0300 | [diff] [blame] | 338 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 339 | protected DriverService driverService; |
| 340 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 341 | private DeviceProviderService providerService; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 342 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 343 | private final InternalDeviceProvider listener = new InternalDeviceProvider(); |
| 344 | |
Simon Hunt | 7a30765 | 2016-06-23 01:17:29 -0700 | [diff] [blame] | 345 | private static final String POLL_PROP_NAME = "portStatsPollFrequency"; |
| 346 | private static final int POLL_INTERVAL = 5; |
| 347 | @Property(name = POLL_PROP_NAME, intValue = POLL_INTERVAL, |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 348 | label = "Frequency (in seconds) for polling switch Port statistics") |
| 349 | private int portStatsPollFrequency = POLL_INTERVAL; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 350 | |
Victor Silva | ff5871b | 2016-10-04 18:08:47 -0300 | [diff] [blame] | 351 | private final Timer timer = new Timer("onos-openflow-portstats-collector"); |
sangyun-han | 07a572f | 2016-07-29 21:14:27 +0900 | [diff] [blame] | 352 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 353 | private HashMap<Dpid, PortStatsCollector> collectors = Maps.newHashMap(); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 354 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 355 | /** |
| 356 | * Creates an OpenFlow device provider. |
| 357 | */ |
| 358 | public OpenFlowDeviceProvider() { |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 359 | super(new ProviderId("of", "org.onosproject.provider.openflow")); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 360 | } |
| 361 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 362 | @Activate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 363 | public void activate(ComponentContext context) { |
| 364 | cfgService.registerProperties(getClass()); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 365 | providerService = providerRegistry.register(this); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 366 | controller.addListener(listener); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 367 | controller.addEventListener(listener); |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 368 | |
Victor Silva | 7944d14 | 2016-07-08 00:14:55 -0300 | [diff] [blame] | 369 | modified(context); |
| 370 | |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 371 | connectInitialDevices(); |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 372 | LOG.info("Started"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Deactivate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 376 | public void deactivate(ComponentContext context) { |
| 377 | cfgService.unregisterProperties(getClass(), false); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 378 | listener.disable(); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 379 | controller.removeListener(listener); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 380 | providerRegistry.unregister(this); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 381 | collectors.values().forEach(PortStatsCollector::stop); |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 382 | collectors.clear(); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 383 | providerService = null; |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 384 | LOG.info("Stopped"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 387 | @Modified |
| 388 | public void modified(ComponentContext context) { |
Victor Silva | 7944d14 | 2016-07-08 00:14:55 -0300 | [diff] [blame] | 389 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 390 | int newPortStatsPollFrequency; |
| 391 | try { |
Simon Hunt | 7a30765 | 2016-06-23 01:17:29 -0700 | [diff] [blame] | 392 | String s = get(properties, POLL_PROP_NAME); |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 393 | newPortStatsPollFrequency = isNullOrEmpty(s) ? portStatsPollFrequency : Integer.parseInt(s.trim()); |
| 394 | |
| 395 | } catch (NumberFormatException | ClassCastException e) { |
| 396 | newPortStatsPollFrequency = portStatsPollFrequency; |
| 397 | } |
| 398 | |
| 399 | if (newPortStatsPollFrequency != portStatsPollFrequency) { |
| 400 | portStatsPollFrequency = newPortStatsPollFrequency; |
| 401 | collectors.values().forEach(psc -> psc.adjustPollInterval(portStatsPollFrequency)); |
| 402 | } |
| 403 | |
| 404 | LOG.info("Settings: portStatsPollFrequency={}", portStatsPollFrequency); |
| 405 | } |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 406 | |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 407 | private void connectInitialDevices() { |
| 408 | for (OpenFlowSwitch sw : controller.getSwitches()) { |
| 409 | try { |
| 410 | listener.switchAdded(new Dpid(sw.getId())); |
| 411 | } catch (Exception e) { |
| 412 | LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); |
| 413 | LOG.debug("Error details:", e); |
| 414 | // disconnect to trigger switch-add later |
| 415 | sw.disconnectSwitch(); |
| 416 | } |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 420 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 421 | public boolean isReachable(DeviceId deviceId) { |
| 422 | OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri())); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 423 | return sw != null && sw.isConnected(); |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 424 | } |
| 425 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 426 | @Override |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 427 | public void triggerProbe(DeviceId deviceId) { |
Madan Jampani | c332876 | 2015-05-31 12:39:27 -0700 | [diff] [blame] | 428 | LOG.debug("Triggering probe on device {}", deviceId); |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 429 | |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 430 | final Dpid dpid = dpid(deviceId.uri()); |
| 431 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 432 | if (sw == null || !sw.isConnected()) { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 433 | LOG.error("Failed to probe device {} on sw={}", deviceId, sw); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 434 | providerService.deviceDisconnected(deviceId); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 435 | return; |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 436 | } else { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 437 | LOG.trace("Confirmed device {} connection", deviceId); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 438 | } |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 439 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 440 | // Prompt an update of port information. We can use any XID for this. |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 441 | OFFactory fact = sw.factory(); |
| 442 | switch (fact.getVersion()) { |
| 443 | case OF_10: |
| 444 | sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build()); |
| 445 | break; |
| 446 | case OF_13: |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 447 | case OF_14: |
| 448 | case OF_15: |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 449 | sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build()); |
| 450 | break; |
| 451 | default: |
| 452 | LOG.warn("Unhandled protocol version"); |
| 453 | } |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 457 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 458 | switch (newRole) { |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 459 | case MASTER: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 460 | controller.setRole(dpid(deviceId.uri()), RoleState.MASTER); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 461 | break; |
| 462 | case STANDBY: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 463 | controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 464 | break; |
| 465 | case NONE: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 466 | controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 467 | break; |
| 468 | default: |
| 469 | LOG.error("Unknown Mastership state : {}", newRole); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 470 | |
| 471 | } |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 472 | LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 475 | @Override |
| 476 | public void changePortState(DeviceId deviceId, PortNumber portNumber, |
| 477 | boolean enable) { |
| 478 | final Dpid dpid = dpid(deviceId.uri()); |
| 479 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 480 | if (sw == null || !sw.isConnected()) { |
| 481 | LOG.error("Failed to change portState on device {}", deviceId); |
| 482 | return; |
| 483 | } |
| 484 | OFPortMod.Builder pmb = sw.factory().buildPortMod(); |
| 485 | OFPort port = OFPort.of((int) portNumber.toLong()); |
| 486 | pmb.setPortNo(port); |
Jimmy Jin | e9b7a02 | 2016-08-12 16:56:48 -0700 | [diff] [blame] | 487 | Set<OFPortConfig> portConfig = EnumSet.noneOf(OFPortConfig.class); |
| 488 | if (!enable) { |
| 489 | portConfig.add(OFPortConfig.PORT_DOWN); |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 490 | } |
Jimmy Jin | e9b7a02 | 2016-08-12 16:56:48 -0700 | [diff] [blame] | 491 | pmb.setConfig(portConfig); |
| 492 | Set<OFPortConfig> portMask = EnumSet.noneOf(OFPortConfig.class); |
| 493 | portMask.add(OFPortConfig.PORT_DOWN); |
| 494 | pmb.setMask(portMask); |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 495 | pmb.setAdvertise(0x0); |
| 496 | for (OFPortDesc pd : sw.getPorts()) { |
| 497 | if (pd.getPortNo().equals(port)) { |
| 498 | pmb.setHwAddr(pd.getHwAddr()); |
| 499 | break; |
| 500 | } |
| 501 | } |
| 502 | sw.sendMsg(Collections.singletonList(pmb.build())); |
| 503 | } |
| 504 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 505 | private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 506 | DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); |
Ray Milkey | 3c4124a | 2016-08-31 12:09:06 -0700 | [diff] [blame] | 507 | Collection<PortStatistics> stats = |
| 508 | buildPortStatistics(deviceId, ImmutableList.copyOf(portStatsEntries)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 509 | providerService.updatePortStatistics(deviceId, stats); |
| 510 | } |
| 511 | |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 512 | |
| 513 | private static String mhzToAnnotation(long freqMhz) { |
| 514 | return Long.toString(Frequency.ofMHz(freqMhz).asHz()); |
| 515 | } |
| 516 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 517 | private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, |
| 518 | List<OFPortStatsEntry> entries) { |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 519 | HashSet<PortStatistics> stats = Sets.newHashSet(); |
| 520 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 521 | for (OFPortStatsEntry entry : entries) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 522 | try { |
Thomas Vachuska | 4e6025e | 2015-06-03 11:25:21 -0700 | [diff] [blame] | 523 | if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 524 | continue; |
| 525 | } |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 526 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder(); |
Laszlo Papp | 9dfb512 | 2018-01-12 21:10:13 +0000 | [diff] [blame] | 527 | boolean propSupported = entry.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion(); |
| 528 | Optional<OFPortStatsPropOptical> optical = propSupported ? |
| 529 | entry.getProperties().stream() |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 530 | .filter(OFPortStatsPropOptical.class::isInstance) |
| 531 | .map(OFPortStatsPropOptical.class::cast) |
Laszlo Papp | 9dfb512 | 2018-01-12 21:10:13 +0000 | [diff] [blame] | 532 | .findAny() : Optional.empty(); |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 533 | if (optical.isPresent()) { |
| 534 | long flags = optical.get().getFlags(); |
| 535 | |
| 536 | int txTune = OFPortStatsOpticalFlagsSerializerVer14.TX_TUNE_VAL; |
| 537 | long txFreq = optical.get().getTxFreqLmda(); |
| 538 | long txOffset = optical.get().getTxOffset(); |
| 539 | long txGridSpan = optical.get().getTxGridSpan(); |
| 540 | annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled"); |
| 541 | annotations.set(AK_TX_FREQ_HZ, mhzToAnnotation(txFreq)); |
| 542 | annotations.set(AK_TX_OFFSET_HZ, mhzToAnnotation(txOffset)); |
| 543 | annotations.set(AK_TX_GRID_SPAN_HZ, mhzToAnnotation(txGridSpan)); |
| 544 | |
| 545 | int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL; |
| 546 | long rxFreq = optical.get().getRxFreqLmda(); |
| 547 | long rxOffset = optical.get().getRxOffset(); |
| 548 | long rxGridSpan = optical.get().getRxGridSpan(); |
| 549 | annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled"); |
| 550 | annotations.set(AK_RX_FREQ_HZ, mhzToAnnotation(rxFreq)); |
| 551 | annotations.set(AK_RX_OFFSET_HZ, mhzToAnnotation(rxOffset)); |
| 552 | annotations.set(AK_RX_GRID_SPAN_HZ, mhzToAnnotation(rxGridSpan)); |
| 553 | |
| 554 | int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL; |
| 555 | int txPwr = optical.get().getTxPwr(); |
| 556 | annotations.set(AK_TX_PWR_FEATURE, ((flags & txPwrVal) != 0) ? "enabled" : "disabled"); |
| 557 | annotations.set(AK_TX_PWR, Integer.toString(txPwr)); |
| 558 | |
| 559 | int rxPwrVal = OFPortStatsOpticalFlagsSerializerVer14.RX_PWR_VAL; |
| 560 | int rxPwr = optical.get().getRxPwr(); |
| 561 | annotations.set(AK_RX_PWR_FEATURE, ((flags & rxPwrVal) != 0) ? "enabled" : "disabled"); |
| 562 | annotations.set(AK_RX_PWR, Integer.toString(rxPwr)); |
| 563 | |
| 564 | int txBias = OFPortStatsOpticalFlagsSerializerVer14.TX_BIAS_VAL; |
| 565 | int biasCurrent = optical.get().getBiasCurrent(); |
| 566 | annotations.set(AK_TX_BIAS_FEATURE, ((flags & txBias) != 0) ? "enabled" : "disabled"); |
| 567 | annotations.set(AK_BIAS_CURRENT, Integer.toString(biasCurrent)); |
| 568 | |
| 569 | int txTemp = OFPortStatsOpticalFlagsSerializerVer14.TX_TEMP_VAL; |
| 570 | int temperature = optical.get().getTemperature(); |
| 571 | annotations.set(AK_TX_TEMP_FEATURE, ((flags & txTemp) != 0) ? "enabled" : "disabled"); |
| 572 | annotations.set(AK_TEMPERATURE, Integer.toString(temperature)); |
| 573 | } |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 574 | DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder(); |
| 575 | DefaultPortStatistics stat = builder.setDeviceId(deviceId) |
| 576 | .setPort(entry.getPortNo().getPortNumber()) |
| 577 | .setPacketsReceived(entry.getRxPackets().getValue()) |
| 578 | .setPacketsSent(entry.getTxPackets().getValue()) |
| 579 | .setBytesReceived(entry.getRxBytes().getValue()) |
| 580 | .setBytesSent(entry.getTxBytes().getValue()) |
| 581 | .setPacketsRxDropped(entry.getRxDropped().getValue()) |
| 582 | .setPacketsTxDropped(entry.getTxDropped().getValue()) |
| 583 | .setPacketsRxErrors(entry.getRxErrors().getValue()) |
| 584 | .setPacketsTxErrors(entry.getTxErrors().getValue()) |
| 585 | .setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()) |
| 586 | .setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()) |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 587 | .setAnnotations(annotations.build()) |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 588 | .build(); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 589 | |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 590 | stats.add(stat); |
| 591 | } catch (Exception e) { |
| 592 | LOG.warn("Unable to process port stats", e); |
| 593 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | return Collections.unmodifiableSet(stats); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener { |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 600 | |
Srikanth Vavilapalli | 78baf58 | 2015-06-05 11:40:14 -0700 | [diff] [blame] | 601 | private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>(); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 602 | private boolean isDisabled = false; |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 603 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 604 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 605 | public void switchAdded(Dpid dpid) { |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 606 | if (providerService == null) { |
| 607 | return; |
| 608 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 609 | DeviceId did = deviceId(uri(dpid)); |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 610 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 611 | if (sw == null) { |
sangyun-han | 147e6f4 | 2016-07-26 17:14:41 +0900 | [diff] [blame] | 612 | LOG.error("Switch {} is not found", dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 613 | return; |
| 614 | } |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 615 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 616 | ChassisId cId = new ChassisId(dpid.value()); |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 617 | |
Victor Silva | ac8dab0 | 2016-11-28 16:33:08 -0300 | [diff] [blame] | 618 | DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder() |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 619 | .set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString()) |
| 620 | .set(AnnotationKeys.CHANNEL_ID, sw.channelId()) |
Victor Silva | ac8dab0 | 2016-11-28 16:33:08 -0300 | [diff] [blame] | 621 | .set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0]); |
| 622 | |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 623 | // FIXME following ignores driver specified by name |
Victor Silva | ac8dab0 | 2016-11-28 16:33:08 -0300 | [diff] [blame] | 624 | Driver driver = driverService.getDriver(sw.manufacturerDescription(), |
| 625 | sw.hardwareDescription(), |
| 626 | sw.softwareDescription()); |
Thomas Vachuska | a79cbf7 | 2017-01-13 15:07:04 -0800 | [diff] [blame] | 627 | // FIXME: The following breaks the STC tests and will require to be revisited. |
| 628 | // if (driver != null) { |
| 629 | // annotationsBuilder.set(AnnotationKeys.DRIVER, driver.name()); |
| 630 | // } |
Victor Silva | ac8dab0 | 2016-11-28 16:33:08 -0300 | [diff] [blame] | 631 | |
| 632 | SparseAnnotations annotations = annotationsBuilder.build(); |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 633 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 634 | DeviceDescription description = |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 635 | new DefaultDeviceDescription(did.uri(), sw.deviceType(), |
Ray Milkey | d3edd03 | 2015-01-16 11:38:58 -0800 | [diff] [blame] | 636 | sw.manufacturerDescription(), |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 637 | sw.hardwareDescription(), |
| 638 | sw.softwareDescription(), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 639 | sw.serialNumber(), |
Thomas Vachuska | 82041f5 | 2014-11-30 22:14:02 -0800 | [diff] [blame] | 640 | cId, annotations); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 641 | providerService.deviceConnected(did, description); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 642 | providerService.updatePorts(did, buildPortDescriptions(sw)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 643 | |
Laszlo Papp | 5817481 | 2018-01-16 13:29:47 +0000 | [diff] [blame] | 644 | if (sw.features().getCapabilities().contains(OFCapabilities.PORT_STATS)) { |
| 645 | PortStatsCollector psc = new PortStatsCollector(timer, sw, portStatsPollFrequency); |
| 646 | stopCollectorIfNeeded(collectors.put(dpid, psc)); |
| 647 | psc.start(); |
| 648 | } |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 649 | |
| 650 | //figure out race condition for collectors.remove() and collectors.put() |
| 651 | if (controller.getSwitch(dpid) == null) { |
| 652 | switchRemoved(dpid); |
| 653 | } |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 656 | private void stopCollectorIfNeeded(PortStatsCollector collector) { |
| 657 | if (collector != null) { |
| 658 | collector.stop(); |
| 659 | } |
| 660 | } |
| 661 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 662 | @Override |
| 663 | public void switchRemoved(Dpid dpid) { |
Victor Silva | 03265dd | 2016-12-08 11:20:36 -0300 | [diff] [blame] | 664 | stopCollectorIfNeeded(collectors.remove(dpid)); |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 665 | if (providerService == null) { |
| 666 | return; |
| 667 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 668 | providerService.deviceDisconnected(deviceId(uri(dpid))); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 669 | } |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 670 | |
| 671 | @Override |
| 672 | public void switchChanged(Dpid dpid) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 673 | LOG.debug("switchChanged({})", dpid); |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 674 | if (providerService == null) { |
| 675 | return; |
| 676 | } |
| 677 | DeviceId did = deviceId(uri(dpid)); |
| 678 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 679 | if (sw == null) { |
sangyun-han | 147e6f4 | 2016-07-26 17:14:41 +0900 | [diff] [blame] | 680 | LOG.error("Switch {} is not found", dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 681 | return; |
| 682 | } |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 683 | final List<PortDescription> ports = buildPortDescriptions(sw); |
| 684 | LOG.debug("switchChanged({}) {}", did, ports); |
| 685 | providerService.updatePorts(did, ports); |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 686 | } |
| 687 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 688 | @Override |
| 689 | public void portChanged(Dpid dpid, OFPortStatus status) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 690 | LOG.debug("portChanged({},{})", dpid, status); |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 691 | PortDescription portDescription = buildPortDescription(status); |
Michal Mach | ce77433 | 2017-01-25 11:02:55 +0100 | [diff] [blame] | 692 | if (status.getReason() != OFPortReason.DELETE) { |
| 693 | providerService.portStatusChanged(deviceId(uri(dpid)), portDescription); |
| 694 | } else { |
| 695 | providerService.deletePort(deviceId(uri(dpid)), portDescription); |
| 696 | } |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 699 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 700 | public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 701 | LOG.debug("receivedRoleReply({},{},{})", dpid, requested, response); |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 702 | MastershipRole request = roleOf(requested); |
| 703 | MastershipRole reply = roleOf(response); |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 704 | providerService.receivedRoleReply(deviceId(uri(dpid)), request, reply); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Translates a RoleState to the corresponding MastershipRole. |
| 709 | * |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 710 | * @param response role state |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 711 | * @return a MastershipRole |
| 712 | */ |
| 713 | private MastershipRole roleOf(RoleState response) { |
| 714 | switch (response) { |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 715 | case MASTER: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 716 | return MastershipRole.MASTER; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 717 | case EQUAL: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 718 | return MastershipRole.STANDBY; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 719 | case SLAVE: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 720 | return MastershipRole.NONE; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 721 | default: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 722 | LOG.warn("unknown role {}", response); |
| 723 | return null; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 724 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 725 | } |
| 726 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 727 | /** |
| 728 | * Builds a list of port descriptions for a given list of ports. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 729 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 730 | * @return list of portdescriptions |
| 731 | */ |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 732 | private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) { |
Yuta HIGUCHI | f83c8cf | 2017-12-17 14:33:49 -0800 | [diff] [blame] | 733 | List<OFPortDesc> ofPorts = sw.getPorts(); |
| 734 | final List<PortDescription> portDescs = new ArrayList<>(ofPorts.size()); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 735 | if (!((Device.Type.ROADM.equals(sw.deviceType())) || |
MaoLu | c201ae4 | 2017-02-06 17:57:01 -0800 | [diff] [blame] | 736 | (Device.Type.OTN.equals(sw.deviceType())) || |
| 737 | (Device.Type.OPTICAL_AMPLIFIER.equals(sw.deviceType())))) { |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 738 | // build regular (=non-optical) Device ports |
Yuta HIGUCHI | f83c8cf | 2017-12-17 14:33:49 -0800 | [diff] [blame] | 739 | ofPorts.forEach(port -> portDescs.add(buildPortDescription(port))); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 740 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 741 | |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 742 | // TODO handle Optical Device, but plain OF devices(1.4 and later) |
| 743 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 744 | OpenFlowOpticalSwitch opsw; |
| 745 | switch (sw.deviceType()) { |
| 746 | case ROADM: |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 747 | case OTN: |
MaoLu | c201ae4 | 2017-02-06 17:57:01 -0800 | [diff] [blame] | 748 | case OPTICAL_AMPLIFIER: |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 749 | opsw = (OpenFlowOpticalSwitch) sw; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 750 | List<OFPortDesc> ports = opsw.getPorts(); |
| 751 | LOG.debug("SW ID {} , ETH- ODU CLT Ports {}", opsw.getId(), ports); |
| 752 | // ODU client ports are reported as ETH |
| 753 | ports.forEach(port -> portDescs.add(buildOduCltPortDescription(port))); |
| 754 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 755 | opsw.getPortTypes().forEach(type -> { |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 756 | List<? extends OFObject> portsOf = opsw.getPortsOf(type); |
| 757 | LOG.debug("Ports Of{}", portsOf); |
| 758 | portsOf.forEach( |
| 759 | op -> { |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 760 | portDescs.add(buildPortDescription(type, op, opsw)); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 761 | } |
| 762 | ); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 763 | }); |
| 764 | break; |
| 765 | case FIBER_SWITCH: |
| 766 | opsw = (OpenFlowOpticalSwitch) sw; |
| 767 | opsw.getPortTypes().forEach(type -> { |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 768 | opsw.getPortsOf(type).forEach(op -> { |
| 769 | if (op instanceof OFPortDesc) { |
| 770 | // ports using standard optical extension |
| 771 | // TODO OFMessage -> PortDescription should |
| 772 | // probably be a Behaviour |
| 773 | portDescs.add(oms(buildPortDescription((OFPortDesc) op))); |
| 774 | } else if (op instanceof OFCalientPortDescStatsEntry) { |
| 775 | // calient extension |
| 776 | portDescs.add(buildPortDescription((OFCalientPortDescStatsEntry) op)); |
| 777 | } else { |
| 778 | LOG.warn("Unexpected FIBER_SWITCH port {} on {}", |
| 779 | op, sw.getStringId()); |
| 780 | } |
| 781 | }); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 782 | }); |
| 783 | break; |
| 784 | default: |
| 785 | break; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 786 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 787 | |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 788 | return portDescs; |
| 789 | } |
| 790 | |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 791 | /** |
| 792 | * Ensures returned PortDescription is an OMS port. |
| 793 | * |
| 794 | * @param descr input PortDescription |
| 795 | * @return OMS PortDescription |
| 796 | */ |
| 797 | private PortDescription oms(PortDescription descr) { |
| 798 | // Hack until OFMessage -> PortDescription transformation |
| 799 | // becomes a Behaviour |
| 800 | if (descr.type() == Type.OMS) { |
| 801 | return descr; |
| 802 | } |
| 803 | |
| 804 | Builder builder = DefaultAnnotations.builder(); |
| 805 | builder.putAll(descr.annotations()); |
| 806 | |
| 807 | // set reasonable default when mandatory key is missing |
| 808 | if (Strings.isNullOrEmpty(descr.annotations().value(AK_MIN_FREQ_HZ))) { |
| 809 | builder.set(AK_MIN_FREQ_HZ, String.valueOf(Spectrum.O_BAND_MIN.asHz())); |
| 810 | } |
| 811 | |
| 812 | if (Strings.isNullOrEmpty(descr.annotations().value(AK_MAX_FREQ_HZ))) { |
| 813 | builder.set(AK_MAX_FREQ_HZ, String.valueOf(Spectrum.O_BAND_MAX.asHz())); |
| 814 | } |
| 815 | |
| 816 | if (Strings.isNullOrEmpty(descr.annotations().value(AK_GRID_HZ))) { |
| 817 | builder.set(AK_GRID_HZ, String.valueOf(Frequency.ofGHz(50).asHz())); |
| 818 | } |
| 819 | |
| 820 | return DefaultPortDescription.builder(descr) |
| 821 | .type(Type.OMS) |
| 822 | .annotations(builder.build()) |
| 823 | .build(); |
| 824 | } |
| 825 | |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 826 | private PortDescription buildOduCltPortDescription(OFPortDesc port) { |
| 827 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 828 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && |
| 829 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 830 | Long portSpeedInMbps = portSpeed(port); |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 831 | CltSignalType sigType = null; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 832 | |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 833 | switch (portSpeedInMbps.toString()) { |
| 834 | case "1000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 835 | sigType = CltSignalType.CLT_1GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 836 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 837 | case "10000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 838 | sigType = CltSignalType.CLT_10GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 839 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 840 | case "40000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 841 | sigType = CltSignalType.CLT_40GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 842 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 843 | case "100000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 844 | sigType = CltSignalType.CLT_100GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 845 | break; |
| 846 | default: |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 847 | throw new RuntimeException("Un recognize OduClt speed: " + portSpeedInMbps.toString()); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | SparseAnnotations annotations = buildOduCltAnnotation(port); |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 851 | return oduCltPortDescription(portNo, enabled, sigType, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | private SparseAnnotations buildOduCltAnnotation(OFPortDesc port) { |
| 855 | SparseAnnotations annotations = null; |
| 856 | String portName = Strings.emptyToNull(port.getName()); |
| 857 | if (portName != null) { |
| 858 | annotations = DefaultAnnotations.builder() |
| 859 | .set(AnnotationKeys.PORT_NAME, portName) |
| 860 | .set(AnnotationKeys.STATIC_PORT, Boolean.TRUE.toString()).build(); |
| 861 | } |
| 862 | return annotations; |
| 863 | } |
| 864 | |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 865 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port, |
| 866 | OpenFlowOpticalSwitch opsw) { |
yjimmyy | 646aa02 | 2016-07-05 12:09:50 -0700 | [diff] [blame] | 867 | if (port instanceof OFPortOptical) { |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 868 | return buildPortDescription(ptype, (OFPortOptical) port, opsw); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 869 | } |
| 870 | return buildPortDescription(ptype, (OFExpPort) port); |
| 871 | } |
| 872 | |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 873 | private boolean matchingOtuPortSignalTypes(OFPortOpticalTransportSignalType sigType, |
| 874 | OduSignalType oduSignalType) { |
| 875 | switch (sigType) { |
| 876 | case OTU2: |
| 877 | if (oduSignalType == OduSignalType.ODU2) { |
| 878 | return true; |
| 879 | } |
| 880 | break; |
| 881 | case OTU4: |
| 882 | if (oduSignalType == OduSignalType.ODU4) { |
| 883 | return true; |
| 884 | } |
| 885 | break; |
| 886 | default: |
| 887 | break; |
| 888 | } |
| 889 | return false; |
| 890 | } |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 891 | /** |
| 892 | * Build a portDescription from a given a port description describing some |
| 893 | * Optical port. |
| 894 | * |
| 895 | * @param ptype description property type. |
| 896 | * @param port the port to build from. |
| 897 | * @return portDescription for the port. |
| 898 | */ |
| 899 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFExpPort port) { |
| 900 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 901 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 902 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 903 | boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 904 | SparseAnnotations annotations = makePortAnnotation(port.getName(), |
| 905 | port.getHwAddr().toString(), |
| 906 | adminDown).build(); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 907 | |
| 908 | OFExpPortDescPropOpticalTransport firstProp = port.getProperties().get(0); |
| 909 | OFPortOpticalTransportSignalType sigType = firstProp.getPortSignalType(); |
| 910 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 911 | PortDescription portDes = null; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 912 | switch (sigType) { |
| 913 | case OMSN: |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 914 | portDes = omsPortDescription(portNo, enabled, |
Rimon Ashkenazy | e320103 | 2016-01-11 14:27:30 +0200 | [diff] [blame] | 915 | FREQ191_7, FREQ191_7.add(FREQ4_4), FREQ50, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 916 | break; |
| 917 | case OCH: |
| 918 | OFExpPortOpticalTransportLayerEntry entry = firstProp.getFeatures().get(0).getValue().get(0); |
| 919 | OFPortOpticalTransportLayerClass layerClass = entry.getLayerClass(); |
| 920 | if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) { |
| 921 | LOG.error("Unsupported layer Class {} ", layerClass); |
| 922 | return null; |
| 923 | } |
| 924 | |
| 925 | // convert to ONOS OduSignalType |
| 926 | OduSignalType oduSignalType = OpenFlowDeviceValueMapper. |
| 927 | lookupOduSignalType((byte) entry.getSignalType()); |
| 928 | //OchSignal is needed for OchPortDescription constructor, |
| 929 | //yet not relevant for tunable OCH port, creating with default parameters |
| 930 | OchSignal signalId = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 1, 1); |
| 931 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 932 | portDes = ochPortDescription(portNo, enabled, |
| 933 | oduSignalType, true, |
| 934 | signalId, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 935 | |
| 936 | break; |
| 937 | case OTU2: |
| 938 | case OTU4: |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 939 | entry = firstProp.getFeatures().get(0).getValue().get(0); |
| 940 | layerClass = entry.getLayerClass(); |
| 941 | if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) { |
| 942 | LOG.error("Unsupported layer Class {} ", layerClass); |
| 943 | return null; |
| 944 | } |
| 945 | |
| 946 | // convert to ONOS OduSignalType |
| 947 | OduSignalType oduSignalTypeOtuPort = OpenFlowDeviceValueMapper. |
| 948 | lookupOduSignalType((byte) entry.getSignalType()); |
| 949 | if (!matchingOtuPortSignalTypes(sigType, oduSignalTypeOtuPort)) { |
| 950 | LOG.error("Wrong oduSignalType {} for OTU Port sigType {} ", oduSignalTypeOtuPort, sigType); |
| 951 | return null; |
| 952 | } |
| 953 | OtuSignalType otuSignalType = |
| 954 | ((sigType == OFPortOpticalTransportSignalType.OTU2) ? OtuSignalType.OTU2 : |
| 955 | OtuSignalType.OTU4); |
HIGUCHI Yuta | 5be3e82 | 2016-05-03 13:51:42 -0700 | [diff] [blame] | 956 | portDes = otuPortDescription(portNo, enabled, otuSignalType, annotations); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 957 | break; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 958 | default: |
| 959 | break; |
| 960 | } |
| 961 | |
| 962 | return portDes; |
| 963 | } |
| 964 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 965 | /** |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 966 | * Creates an annotation builder for the port name if one is available. |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 967 | * |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 968 | * @param portName the port name |
| 969 | * @param portMac the port mac |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 970 | * @param adminDown the port admin state |
| 971 | * @return annotation builder containing port admin state, port name |
| 972 | * and/or port MAC if any of the two is found |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 973 | */ |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 974 | private DefaultAnnotations.Builder makePortAnnotation(String portName, String portMac, boolean adminDown) { |
Andrea Campanella | c8b871a | 2017-01-19 13:53:05 -0800 | [diff] [blame] | 975 | DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 976 | String pName = Strings.emptyToNull(portName); |
| 977 | String pMac = Strings.emptyToNull(portMac); |
Andrea Campanella | c8b871a | 2017-01-19 13:53:05 -0800 | [diff] [blame] | 978 | if (pName != null) { |
| 979 | builder.set(AnnotationKeys.PORT_NAME, pName); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 980 | } |
Andrea Campanella | c8b871a | 2017-01-19 13:53:05 -0800 | [diff] [blame] | 981 | if (pMac != null) { |
| 982 | builder.set(AnnotationKeys.PORT_MAC, pMac); |
| 983 | } |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 984 | String adminState = adminDown ? "disabled" : "enabled"; |
| 985 | builder.set(AnnotationKeys.ADMIN_STATE, adminState); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 986 | return builder; |
| 987 | } |
| 988 | |
| 989 | private String mhzToAnnotation(long freqMhz) { |
Laszlo Papp | 7cf6037 | 2018-01-11 00:06:43 +0000 | [diff] [blame] | 990 | return OpenFlowDeviceProvider.mhzToAnnotation(freqMhz); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 991 | } |
| 992 | |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 993 | private String lambdaToAnnotationHz(long lambda) { |
| 994 | // ref. OF1.5: wavelength (lambda) as nm * 100 |
| 995 | |
| 996 | long c = 299792458; // speed of light in m/s |
| 997 | // f = c / λ |
| 998 | // (m/s) * (nm/m) / (nm * 100) * 100 |
| 999 | // annotations is in Hz |
Laszlo Papp | 73f9aea | 2018-01-15 19:23:45 +0000 | [diff] [blame] | 1000 | return Long.toString(lambda == 0 ? lambda : (c * 1_000_000_000 / lambda * 100)); |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1003 | private PortDescription buildPortDescription14(OFPortDesc port) { |
| 1004 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 1005 | boolean enabled = |
| 1006 | !port.getState().contains(OFPortState.LINK_DOWN) && |
| 1007 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 1008 | boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1009 | Builder annotations = makePortAnnotation(port.getName(), |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 1010 | port.getHwAddr().toString(), |
| 1011 | adminDown); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1012 | |
| 1013 | Optional<OFPortDescPropEthernet> ether = port.getProperties().stream() |
| 1014 | .filter(OFPortDescPropEthernet.class::isInstance) |
| 1015 | .map(OFPortDescPropEthernet.class::cast) |
| 1016 | .findAny(); |
| 1017 | if (ether.isPresent()) { |
| 1018 | // ethernet port |
| 1019 | // TODO parse other part of OFPortDescPropEthernet if necessary |
| 1020 | return new DefaultPortDescription(portNo, |
| 1021 | enabled, |
| 1022 | COPPER, |
| 1023 | portSpeed(port), |
| 1024 | annotations.build()); |
| 1025 | } |
| 1026 | |
| 1027 | Optional<OFPortDescPropOptical> optical = port.getProperties().stream() |
| 1028 | .filter(OFPortDescPropOptical.class::isInstance) |
| 1029 | .map(OFPortDescPropOptical.class::cast) |
| 1030 | .findAny(); |
| 1031 | if (optical.isPresent()) { |
| 1032 | // optical port |
| 1033 | |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1034 | // FIXME is there a OF version neutral way to access |
| 1035 | // OFOpticalPortFeaturesSerializerVer14 |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1036 | |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1037 | long supported = optical.get().getSupported(); |
| 1038 | long rxMin = optical.get().getRxMinFreqLmda(); |
| 1039 | long rxMax = optical.get().getRxMaxFreqLmda(); |
| 1040 | long rxGrid = optical.get().getRxGridFreqLmda(); |
| 1041 | long txMin = optical.get().getTxMinFreqLmda(); |
| 1042 | long txMax = optical.get().getTxMaxFreqLmda(); |
| 1043 | long txGrid = optical.get().getTxGridFreqLmda(); |
| 1044 | |
| 1045 | int txTune = OFOpticalPortFeaturesSerializerVer14.TX_TUNE_VAL; |
| 1046 | int rxTune = OFOpticalPortFeaturesSerializerVer14.RX_TUNE_VAL; |
| 1047 | annotations.set(AK_TX_TUNE_FEATURE, |
| 1048 | ((supported & txTune) != 0) ? "enabled" : "disabled"); |
| 1049 | annotations.set(AK_RX_TUNE_FEATURE, |
| 1050 | ((supported & rxTune) != 0) ? "enabled" : "disabled"); |
| 1051 | |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1052 | // wire value for OFOpticalPortFeatures.USE_FREQ |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1053 | long useFreq = OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL; |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1054 | if ((supported & useFreq) != 0) { |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1055 | // unit is in Frequency Mhz |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1056 | annotations.set(AK_RX_MIN_FREQ_HZ, mhzToAnnotation(rxMin)); |
| 1057 | annotations.set(AK_RX_MAX_FREQ_HZ, mhzToAnnotation(rxMax)); |
| 1058 | annotations.set(AK_RX_GRID_HZ, mhzToAnnotation(rxGrid)); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1059 | |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1060 | annotations.set(AK_TX_MIN_FREQ_HZ, mhzToAnnotation(txMin)); |
| 1061 | annotations.set(AK_TX_MAX_FREQ_HZ, mhzToAnnotation(txMax)); |
| 1062 | annotations.set(AK_TX_GRID_HZ, mhzToAnnotation(txGrid)); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1063 | |
| 1064 | // FIXME pretty confident this is not going to happen |
| 1065 | // unless Device models Tx/Rx ports as separate port |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1066 | if (rxMin == txMin) { |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1067 | annotations.set(AK_MIN_FREQ_HZ, |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1068 | mhzToAnnotation(rxMin)); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1069 | } |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1070 | if (rxMax == txMax) { |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1071 | annotations.set(AK_MAX_FREQ_HZ, |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1072 | mhzToAnnotation(rxMax)); |
| 1073 | } |
| 1074 | if (rxGrid == txGrid) { |
| 1075 | annotations.set(AK_GRID_HZ, |
| 1076 | mhzToAnnotation(rxGrid)); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | } else { |
| 1080 | // unit is in Lambda nm * 100 |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1081 | annotations.set(AK_RX_MIN_FREQ_HZ, lambdaToAnnotationHz(rxMin)); |
| 1082 | annotations.set(AK_RX_MAX_FREQ_HZ, lambdaToAnnotationHz(rxMax)); |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1083 | annotations.set(AK_RX_GRID_HZ, lambdaToAnnotationHz(rxGrid)); |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1084 | |
| 1085 | annotations.set(AK_TX_MIN_FREQ_HZ, lambdaToAnnotationHz(txMin)); |
| 1086 | annotations.set(AK_TX_MAX_FREQ_HZ, lambdaToAnnotationHz(txMax)); |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1087 | annotations.set(AK_TX_GRID_HZ, lambdaToAnnotationHz(txGrid)); |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1088 | |
| 1089 | // FIXME pretty confident this is not going to happen |
| 1090 | // unless Device models Tx/Rx ports as separate port |
| 1091 | if (rxMin == txMin) { |
| 1092 | annotations.set(AK_MIN_FREQ_HZ, |
| 1093 | lambdaToAnnotationHz(rxMin)); |
| 1094 | } |
| 1095 | if (rxMax == txMax) { |
| 1096 | annotations.set(AK_MAX_FREQ_HZ, |
| 1097 | lambdaToAnnotationHz(rxMax)); |
| 1098 | } |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1099 | if (rxGrid == txGrid) { |
| 1100 | annotations.set(AK_GRID_HZ, |
| 1101 | lambdaToAnnotationHz(rxGrid)); |
| 1102 | } |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1103 | |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1104 | } |
Laszlo Papp | 20cfb6f | 2018-01-08 16:06:53 +0000 | [diff] [blame] | 1105 | |
| 1106 | int txPwr = OFOpticalPortFeaturesSerializerVer14.TX_PWR_VAL; |
| 1107 | long txPwrMin = optical.get().getTxPwrMin(); |
| 1108 | long txPwrMax = optical.get().getTxPwrMax(); |
| 1109 | annotations.set(AK_TX_PWR_FEATURE, ((supported & txPwr) != 0) ? "enabled" : "disabled"); |
| 1110 | annotations.set(AK_TX_PWR_MIN, Long.toString(txPwrMin)); |
| 1111 | annotations.set(AK_TX_PWR_MAX, Long.toString(txPwrMax)); |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1112 | |
| 1113 | // TODO How to determine appropriate port type? |
| 1114 | |
| 1115 | return new DefaultPortDescription(portNo, |
| 1116 | enabled, |
| 1117 | FIBER, |
| 1118 | portSpeed(port), |
| 1119 | annotations.build()); |
| 1120 | } |
| 1121 | |
| 1122 | // fall back default |
| 1123 | return new DefaultPortDescription(portNo, |
| 1124 | enabled, |
| 1125 | COPPER, |
| 1126 | portSpeed(port), |
| 1127 | annotations.build()); |
| 1128 | |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | /** |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1132 | * Build a portDescription from a given Ethernet port description. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 1133 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 1134 | * @param port the port to build from. |
| 1135 | * @return portDescription for the port. |
| 1136 | */ |
| 1137 | private PortDescription buildPortDescription(OFPortDesc port) { |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1138 | if (port.getVersion().wireVersion >= OFVersion.OF_14.getWireVersion()) { |
| 1139 | return buildPortDescription14(port); |
| 1140 | } |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 1141 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 1142 | boolean enabled = |
| 1143 | !port.getState().contains(OFPortState.LINK_DOWN) && |
| 1144 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 1145 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 1146 | boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 1147 | SparseAnnotations annotations = makePortAnnotation(port.getName(), |
| 1148 | port.getHwAddr().toString(), |
| 1149 | adminDown).build(); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 1150 | return new DefaultPortDescription(portNo, enabled, type, |
| 1151 | portSpeed(port), annotations); |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 1152 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 1153 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1154 | /** |
| 1155 | * Build a portDescription from a given a port description describing some |
| 1156 | * Optical port. |
| 1157 | * |
| 1158 | * @param port description property type. |
| 1159 | * @param port the port to build from. |
| 1160 | * @return portDescription for the port. |
| 1161 | */ |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 1162 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port, |
| 1163 | OpenFlowOpticalSwitch opsw) { |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 1164 | checkArgument(!port.getDesc().isEmpty()); |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 1165 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1166 | // Minimally functional fixture. This needs to be fixed as we add better support. |
| 1167 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 1168 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1169 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 1170 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 1171 | boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 1172 | SparseAnnotations annotations = makePortAnnotation(port.getName(), |
| 1173 | port.getHwAddr().toString(), |
| 1174 | adminDown).build(); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1175 | |
| 1176 | if (port.getVersion() == OFVersion.OF_13 |
| 1177 | && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) { |
| 1178 | // At this point, not much is carried in the optical port message. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 1179 | LOG.debug("Optical transport port message {}", port.toString()); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1180 | } else { |
| 1181 | // removable once 1.4+ support complete. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 1182 | LOG.debug("Unsupported optical port properties"); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1183 | } |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 1184 | |
| 1185 | OFPortDescPropOpticalTransport desc = port.getDesc().get(0); |
| 1186 | switch (desc.getPortSignalType()) { |
| 1187 | // FIXME: use constants once loxi has full optical extensions |
| 1188 | case 2: // OMS port |
| 1189 | // Assume complete optical spectrum and 50 GHz grid |
Jimmy Yan | 4deb03b | 2016-06-24 10:53:54 -0700 | [diff] [blame] | 1190 | Set<OchSignal> signals = null; |
| 1191 | if (opsw instanceof HandlerBehaviour) { |
| 1192 | DriverHandler driverHandler = ((HandlerBehaviour) opsw).handler(); |
| 1193 | if (driverHandler != null && driverHandler.hasBehaviour(LambdaQuery.class)) { |
| 1194 | try { |
| 1195 | signals = driverHandler.behaviour(LambdaQuery.class).queryLambdas(portNo); |
| 1196 | } catch (NullPointerException e) { |
| 1197 | signals = null; |
| 1198 | } |
| 1199 | } |
| 1200 | } |
| 1201 | Frequency minFreq; |
| 1202 | Frequency maxFreq; |
| 1203 | Frequency channelSpacing; |
| 1204 | if (signals == null || signals.isEmpty()) { |
| 1205 | minFreq = Spectrum.U_BAND_MIN; |
| 1206 | maxFreq = Spectrum.O_BAND_MAX; |
| 1207 | channelSpacing = Frequency.ofGHz(50); |
| 1208 | } else { |
| 1209 | Comparator<OchSignal> compare = |
| 1210 | (OchSignal a, OchSignal b) -> a.spacingMultiplier() - b.spacingMultiplier(); |
| 1211 | OchSignal minOch = Collections.min(signals, compare); |
| 1212 | OchSignal maxOch = Collections.max(signals, compare); |
| 1213 | minFreq = minOch.centralFrequency(); |
| 1214 | maxFreq = maxOch.centralFrequency(); |
| 1215 | channelSpacing = minOch.channelSpacing().frequency(); |
| 1216 | } |
| 1217 | return omsPortDescription(portNo, enabled, minFreq, |
| 1218 | maxFreq, channelSpacing, annotations); |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 1219 | case 5: // OCH port |
| 1220 | OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4); |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 1221 | return ochPortDescription(portNo, enabled, OduSignalType.ODU4, |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 1222 | true, signal, annotations); |
| 1223 | default: |
| 1224 | break; |
| 1225 | } |
| 1226 | |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 1227 | return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 1230 | /** |
| 1231 | * Build a portDescription from a given port description describing a fiber switch optical port. |
| 1232 | * |
| 1233 | * @param port description property type. |
| 1234 | * @param port the port to build from. |
| 1235 | * @return portDescription for the port. |
| 1236 | */ |
| 1237 | private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) { |
| 1238 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 1239 | |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 1240 | // Use the alias name if it's available |
| 1241 | String name = port.getName(); |
| 1242 | List<OFCalientPortDescProp> props = port.getProperties(); |
Jon Hall | cbd1b39 | 2017-01-18 20:15:44 -0800 | [diff] [blame] | 1243 | if (props != null && !props.isEmpty()) { |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 1244 | OFCalientPortDescPropOptical propOptical = (OFCalientPortDescPropOptical) props.get(0); |
| 1245 | if (propOptical != null) { |
| 1246 | name = propOptical.getInAlias(); |
| 1247 | } |
| 1248 | } |
| 1249 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 1250 | // FIXME when Calient OF agent reports port status |
| 1251 | boolean enabled = true; |
mskala | c584bd9 | 2017-11-28 15:51:17 +0100 | [diff] [blame] | 1252 | boolean adminDown = false; |
| 1253 | SparseAnnotations annotations = makePortAnnotation(name, port.getHwAddr().toString(), adminDown).build(); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 1254 | |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 1255 | // S160 data sheet |
| 1256 | // Wavelength range: 1260 - 1630 nm, grid is irrelevant for this type of switch |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 1257 | return omsPortDescription(portNo, enabled, |
Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame] | 1258 | Spectrum.O_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(50), annotations); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 1261 | private PortDescription buildPortDescription(OFPortStatus status) { |
| 1262 | OFPortDesc port = status.getDesc(); |
| 1263 | if (status.getReason() != OFPortReason.DELETE) { |
| 1264 | return buildPortDescription(port); |
| 1265 | } else { |
Yuta HIGUCHI | 6512f3e | 2017-05-18 17:21:24 -0700 | [diff] [blame] | 1266 | PortDescription desc = buildPortDescription(port); |
| 1267 | if (desc.isEnabled()) { |
| 1268 | return DefaultPortDescription.builder(desc) |
| 1269 | .isEnabled(false) |
| 1270 | .build(); |
| 1271 | } |
| 1272 | return desc; |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1276 | /** |
| 1277 | * Returns port speed in Mbps. |
| 1278 | * |
| 1279 | * @param port description to parse |
| 1280 | * @return port speed in Mbps |
| 1281 | */ |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 1282 | private long portSpeed(OFPortDesc port) { |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1283 | if (port.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion()) { |
| 1284 | // OFPortDescPropEthernet |
| 1285 | return port.getProperties().stream() |
| 1286 | .filter(OFPortDescPropEthernet.class::isInstance) |
| 1287 | .map(OFPortDescPropEthernet.class::cast) |
| 1288 | .mapToLong(OFPortDescPropEthernet::getCurrSpeed) |
| 1289 | .map(kbps -> kbps / KBPS) |
| 1290 | .findAny() |
| 1291 | .orElse(PortSpeed.SPEED_NONE.getSpeedBps() / MBPS); |
| 1292 | } |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 1293 | if (port.getVersion() == OFVersion.OF_13) { |
Charles Chan | 25b7732 | 2015-12-13 01:00:56 -0800 | [diff] [blame] | 1294 | // Note: getCurrSpeed() returns a value in kbps (this also applies to OF_11 and OF_12) |
| 1295 | return port.getCurrSpeed() / KBPS; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 1296 | } |
Yuta HIGUCHI | 2341e60 | 2017-03-08 20:10:08 -0800 | [diff] [blame] | 1297 | // < OF1.3 |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 1298 | PortSpeed portSpeed = PortSpeed.SPEED_NONE; |
| 1299 | for (OFPortFeatures feat : port.getCurr()) { |
| 1300 | portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed()); |
| 1301 | } |
Thomas Vachuska | 98eda53 | 2014-10-29 17:31:02 -0700 | [diff] [blame] | 1302 | return portSpeed.getSpeedBps() / MBPS; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 1303 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 1304 | |
| 1305 | @Override |
| 1306 | public void handleMessage(Dpid dpid, OFMessage msg) { |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 1307 | if (isDisabled) { |
| 1308 | return; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 1309 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 1310 | |
| 1311 | try { |
| 1312 | switch (msg.getType()) { |
| 1313 | case STATS_REPLY: |
| 1314 | if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { |
| 1315 | OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; |
| 1316 | List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); |
| 1317 | if (portStatsReplyList == null) { |
Madan Jampani | 84382b9 | 2016-06-22 08:26:49 -0700 | [diff] [blame] | 1318 | portStatsReplyList = Lists.newCopyOnWriteArrayList(); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 1319 | } |
| 1320 | portStatsReplyList.addAll(portStatsReply.getEntries()); |
| 1321 | portStatsReplies.put(dpid, portStatsReplyList); |
| 1322 | if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
Charles Chan | b3ef0db | 2016-05-03 11:11:00 -0700 | [diff] [blame] | 1323 | List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid); |
| 1324 | if (statsEntries != null) { |
| 1325 | pushPortMetrics(dpid, statsEntries); |
| 1326 | statsEntries.clear(); |
| 1327 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 1328 | } |
yjimmyy | 646aa02 | 2016-07-05 12:09:50 -0700 | [diff] [blame] | 1329 | } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.EXPERIMENTER) { |
| 1330 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
sangyun-han | 147e6f4 | 2016-07-26 17:14:41 +0900 | [diff] [blame] | 1331 | if (sw == null) { |
| 1332 | LOG.error("Switch {} is not found", dpid); |
| 1333 | break; |
| 1334 | } |
yjimmyy | 646aa02 | 2016-07-05 12:09:50 -0700 | [diff] [blame] | 1335 | if (sw instanceof OpenFlowOpticalSwitch) { |
| 1336 | // Optical switch uses experimenter stats message to update power |
| 1337 | List<PortDescription> portDescs = |
| 1338 | ((OpenFlowOpticalSwitch) sw).processExpPortStats(msg); |
| 1339 | if (!portDescs.isEmpty()) { |
| 1340 | providerService.updatePorts(DeviceId.deviceId(Dpid.uri(dpid)), portDescs); |
| 1341 | } |
| 1342 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 1343 | } |
| 1344 | break; |
| 1345 | case ERROR: |
| 1346 | if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) { |
| 1347 | LOG.error("port mod failed"); |
| 1348 | } |
| 1349 | default: |
| 1350 | break; |
| 1351 | } |
| 1352 | } catch (IllegalStateException e) { |
| 1353 | // system is shutting down and the providerService is no longer |
| 1354 | // valid. Messages cannot be processed. |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | private void disable() { |
| 1359 | isDisabled = true; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 1360 | } |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 1361 | } |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 1362 | |
| 1363 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 1364 | } |