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