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