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