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