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