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