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