Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.of.device.impl; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 17 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 20 | import static org.onlab.util.Tools.get; |
| 21 | import static org.onosproject.net.DeviceId.deviceId; |
| 22 | import static org.onosproject.net.Port.Type.COPPER; |
| 23 | import static org.onosproject.net.Port.Type.FIBER; |
| 24 | import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription; |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 25 | import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 26 | import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription; |
HIGUCHI Yuta | 5be3e82 | 2016-05-03 13:51:42 -0700 | [diff] [blame] | 27 | import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription; |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 28 | import static org.onosproject.openflow.controller.Dpid.dpid; |
| 29 | import static org.onosproject.openflow.controller.Dpid.uri; |
| 30 | import static org.slf4j.LoggerFactory.getLogger; |
| 31 | |
| 32 | import java.util.ArrayList; |
| 33 | import java.util.Collection; |
| 34 | import java.util.Collections; |
| 35 | import java.util.Dictionary; |
| 36 | import java.util.HashMap; |
| 37 | import java.util.HashSet; |
| 38 | import java.util.List; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 39 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 40 | import org.apache.felix.scr.annotations.Activate; |
| 41 | import org.apache.felix.scr.annotations.Component; |
| 42 | import org.apache.felix.scr.annotations.Deactivate; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 43 | import org.apache.felix.scr.annotations.Modified; |
| 44 | import org.apache.felix.scr.annotations.Property; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 45 | import org.apache.felix.scr.annotations.Reference; |
| 46 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 47 | import org.onlab.packet.ChassisId; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 48 | import org.onlab.util.Frequency; |
| 49 | import org.onlab.util.Spectrum; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 50 | import org.onosproject.cfg.ComponentConfigService; |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 51 | import org.onosproject.net.AnnotationKeys; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 52 | import org.onosproject.net.ChannelSpacing; |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 53 | import org.onosproject.net.CltSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 54 | import org.onosproject.net.DefaultAnnotations; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 55 | import org.onosproject.net.Device; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 56 | import org.onosproject.net.DeviceId; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 57 | import org.onosproject.net.GridType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 58 | import org.onosproject.net.MastershipRole; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 59 | import org.onosproject.net.OchSignal; |
| 60 | import org.onosproject.net.OduSignalType; |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 61 | import org.onosproject.net.OtuSignalType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 62 | import org.onosproject.net.Port; |
| 63 | import org.onosproject.net.PortNumber; |
| 64 | import org.onosproject.net.SparseAnnotations; |
| 65 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 66 | import org.onosproject.net.device.DefaultPortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 67 | import org.onosproject.net.device.DefaultPortStatistics; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 68 | import org.onosproject.net.device.DeviceDescription; |
| 69 | import org.onosproject.net.device.DeviceProvider; |
| 70 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 71 | import org.onosproject.net.device.DeviceProviderService; |
| 72 | import org.onosproject.net.device.PortDescription; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 73 | import org.onosproject.net.device.PortStatistics; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 74 | import org.onosproject.net.provider.AbstractProvider; |
| 75 | import org.onosproject.net.provider.ProviderId; |
| 76 | import org.onosproject.openflow.controller.Dpid; |
| 77 | import org.onosproject.openflow.controller.OpenFlowController; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 78 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 79 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 80 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
| 81 | import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 82 | import org.onosproject.openflow.controller.PortDescPropertyType; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 83 | import org.onosproject.openflow.controller.RoleState; |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 84 | import org.osgi.service.component.ComponentContext; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 85 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescProp; |
| 86 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescPropOptical; |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 87 | import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 88 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 89 | import org.projectfloodlight.openflow.protocol.OFErrorType; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 90 | import org.projectfloodlight.openflow.protocol.OFExpPort; |
| 91 | import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport; |
| 92 | import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry; |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 93 | import org.projectfloodlight.openflow.protocol.OFFactory; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 94 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 95 | import org.projectfloodlight.openflow.protocol.OFObject; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 96 | import org.projectfloodlight.openflow.protocol.OFPortConfig; |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 97 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 98 | import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 99 | import org.projectfloodlight.openflow.protocol.OFPortFeatures; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 100 | import org.projectfloodlight.openflow.protocol.OFPortMod; |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 101 | import org.projectfloodlight.openflow.protocol.OFPortOptical; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 102 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass; |
| 103 | import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType; |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 104 | import org.projectfloodlight.openflow.protocol.OFPortReason; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 105 | import org.projectfloodlight.openflow.protocol.OFPortState; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 106 | import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; |
| 107 | import org.projectfloodlight.openflow.protocol.OFPortStatsReply; |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 108 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 109 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 110 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 111 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 112 | import org.projectfloodlight.openflow.protocol.OFVersion; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 113 | import org.projectfloodlight.openflow.types.OFPort; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 114 | import org.projectfloodlight.openflow.types.PortSpeed; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 115 | import org.slf4j.Logger; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 116 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 117 | import com.google.common.base.Strings; |
| 118 | import com.google.common.collect.Lists; |
| 119 | import com.google.common.collect.Maps; |
| 120 | import com.google.common.collect.Sets; |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 121 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 122 | /** |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 123 | * Provider which uses an OpenFlow controller to detect network |
tom | e06f855 | 2014-08-26 16:58:42 -0700 | [diff] [blame] | 124 | * infrastructure devices. |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 125 | */ |
tom | b1260e4 | 2014-08-26 18:39:57 -0700 | [diff] [blame] | 126 | @Component(immediate = true) |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 127 | public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider { |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 128 | |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 129 | private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 130 | |
Charles Chan | 25b7732 | 2015-12-13 01:00:56 -0800 | [diff] [blame] | 131 | //TODO consider renaming KBPS and MBPS (as they are used to convert by division) |
| 132 | private static final long KBPS = 1_000; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 133 | private static final long MBPS = 1_000 * 1_000; |
Rimon Ashkenazy | e320103 | 2016-01-11 14:27:30 +0200 | [diff] [blame] | 134 | private static final Frequency FREQ50 = Frequency.ofGHz(50); |
| 135 | private static final Frequency FREQ191_7 = Frequency.ofGHz(191_700); |
Sho SHIMIZU | 00762ee | 2016-01-05 16:32:24 -0800 | [diff] [blame] | 136 | private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 137 | |
| 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 139 | protected DeviceProviderRegistry providerRegistry; |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 140 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 142 | protected OpenFlowController controller; |
| 143 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 144 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 145 | protected ComponentConfigService cfgService; |
| 146 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 147 | private DeviceProviderService providerService; |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 148 | |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 149 | private final InternalDeviceProvider listener = new InternalDeviceProvider(); |
| 150 | |
Simon Hunt | 7a30765 | 2016-06-23 01:17:29 -0700 | [diff] [blame] | 151 | private static final String POLL_PROP_NAME = "portStatsPollFrequency"; |
| 152 | private static final int POLL_INTERVAL = 5; |
| 153 | @Property(name = POLL_PROP_NAME, intValue = POLL_INTERVAL, |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 154 | label = "Frequency (in seconds) for polling switch Port statistics") |
| 155 | private int portStatsPollFrequency = POLL_INTERVAL; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 156 | |
| 157 | private HashMap<Dpid, PortStatsCollector> collectors = Maps.newHashMap(); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 158 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Creates an OpenFlow device provider. |
| 161 | */ |
| 162 | public OpenFlowDeviceProvider() { |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 163 | super(new ProviderId("of", "org.onosproject.provider.openflow")); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 164 | } |
| 165 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 166 | @Activate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 167 | public void activate(ComponentContext context) { |
| 168 | cfgService.registerProperties(getClass()); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 169 | providerService = providerRegistry.register(this); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 170 | controller.addListener(listener); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 171 | controller.addEventListener(listener); |
Jian Li | 152b885 | 2015-12-07 14:47:25 -0800 | [diff] [blame] | 172 | |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 173 | connectInitialDevices(); |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 174 | LOG.info("Started"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Deactivate |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 178 | public void deactivate(ComponentContext context) { |
| 179 | cfgService.unregisterProperties(getClass(), false); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 180 | listener.disable(); |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 181 | controller.removeListener(listener); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 182 | providerRegistry.unregister(this); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 183 | collectors.values().forEach(PortStatsCollector::stop); |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 184 | collectors.clear(); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 185 | providerService = null; |
alshabib | a89cc58 | 2014-09-09 16:43:00 -0700 | [diff] [blame] | 186 | LOG.info("Stopped"); |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 189 | @Modified |
| 190 | public void modified(ComponentContext context) { |
| 191 | Dictionary<?, ?> properties = context.getProperties(); |
| 192 | int newPortStatsPollFrequency; |
| 193 | try { |
Simon Hunt | 7a30765 | 2016-06-23 01:17:29 -0700 | [diff] [blame] | 194 | String s = get(properties, POLL_PROP_NAME); |
Dusan Pajin | bab8a5e | 2015-07-24 17:37:19 +0200 | [diff] [blame] | 195 | newPortStatsPollFrequency = isNullOrEmpty(s) ? portStatsPollFrequency : Integer.parseInt(s.trim()); |
| 196 | |
| 197 | } catch (NumberFormatException | ClassCastException e) { |
| 198 | newPortStatsPollFrequency = portStatsPollFrequency; |
| 199 | } |
| 200 | |
| 201 | if (newPortStatsPollFrequency != portStatsPollFrequency) { |
| 202 | portStatsPollFrequency = newPortStatsPollFrequency; |
| 203 | collectors.values().forEach(psc -> psc.adjustPollInterval(portStatsPollFrequency)); |
| 204 | } |
| 205 | |
| 206 | LOG.info("Settings: portStatsPollFrequency={}", portStatsPollFrequency); |
| 207 | } |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 208 | |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 209 | private void connectInitialDevices() { |
| 210 | for (OpenFlowSwitch sw : controller.getSwitches()) { |
| 211 | try { |
| 212 | listener.switchAdded(new Dpid(sw.getId())); |
| 213 | } catch (Exception e) { |
| 214 | LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); |
| 215 | LOG.debug("Error details:", e); |
| 216 | // disconnect to trigger switch-add later |
| 217 | sw.disconnectSwitch(); |
| 218 | } |
| 219 | PortStatsCollector psc = new PortStatsCollector(sw, portStatsPollFrequency); |
| 220 | psc.start(); |
| 221 | collectors.put(new Dpid(sw.getId()), psc); |
| 222 | } |
| 223 | } |
| 224 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 225 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 226 | public boolean isReachable(DeviceId deviceId) { |
| 227 | OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri())); |
Thomas Vachuska | d07c092 | 2015-10-06 14:48:06 -0700 | [diff] [blame] | 228 | return sw != null && sw.isConnected(); |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 229 | } |
| 230 | |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 231 | @Override |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 232 | public void triggerProbe(DeviceId deviceId) { |
Madan Jampani | c332876 | 2015-05-31 12:39:27 -0700 | [diff] [blame] | 233 | LOG.debug("Triggering probe on device {}", deviceId); |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 234 | |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 235 | final Dpid dpid = dpid(deviceId.uri()); |
| 236 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 237 | if (sw == null || !sw.isConnected()) { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 238 | LOG.error("Failed to probe device {} on sw={}", deviceId, sw); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 239 | providerService.deviceDisconnected(deviceId); |
Thomas Vachuska | 74bcd92 | 2015-06-02 13:08:57 -0700 | [diff] [blame] | 240 | return; |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 241 | } else { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 242 | LOG.trace("Confirmed device {} connection", deviceId); |
Yuta HIGUCHI | 802d0e8 | 2014-10-31 16:07:37 -0700 | [diff] [blame] | 243 | } |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 244 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 245 | // 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] | 246 | OFFactory fact = sw.factory(); |
| 247 | switch (fact.getVersion()) { |
| 248 | case OF_10: |
| 249 | sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build()); |
| 250 | break; |
| 251 | case OF_13: |
| 252 | sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build()); |
| 253 | break; |
| 254 | default: |
| 255 | LOG.warn("Unhandled protocol version"); |
| 256 | } |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | @Override |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 260 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 261 | switch (newRole) { |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 262 | case MASTER: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 263 | controller.setRole(dpid(deviceId.uri()), RoleState.MASTER); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 264 | break; |
| 265 | case STANDBY: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 266 | controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 267 | break; |
| 268 | case NONE: |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 269 | controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 270 | break; |
| 271 | default: |
| 272 | LOG.error("Unknown Mastership state : {}", newRole); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 273 | |
| 274 | } |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 275 | LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId); |
tom | ab21e7c | 2014-08-26 15:23:08 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 278 | @Override |
| 279 | public void changePortState(DeviceId deviceId, PortNumber portNumber, |
| 280 | boolean enable) { |
| 281 | final Dpid dpid = dpid(deviceId.uri()); |
| 282 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 283 | if (sw == null || !sw.isConnected()) { |
| 284 | LOG.error("Failed to change portState on device {}", deviceId); |
| 285 | return; |
| 286 | } |
| 287 | OFPortMod.Builder pmb = sw.factory().buildPortMod(); |
| 288 | OFPort port = OFPort.of((int) portNumber.toLong()); |
| 289 | pmb.setPortNo(port); |
| 290 | if (enable) { |
| 291 | pmb.setConfig(0x0); // port_down bit 0 |
| 292 | } else { |
| 293 | pmb.setConfig(0x1); // port_down bit 1 |
| 294 | } |
| 295 | pmb.setMask(0x1); |
| 296 | pmb.setAdvertise(0x0); |
| 297 | for (OFPortDesc pd : sw.getPorts()) { |
| 298 | if (pd.getPortNo().equals(port)) { |
| 299 | pmb.setHwAddr(pd.getHwAddr()); |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | sw.sendMsg(Collections.singletonList(pmb.build())); |
| 304 | } |
| 305 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 306 | private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 307 | DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 308 | Collection<PortStatistics> stats = buildPortStatistics(deviceId, portStatsEntries); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 309 | providerService.updatePortStatistics(deviceId, stats); |
| 310 | } |
| 311 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 312 | private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, |
| 313 | List<OFPortStatsEntry> entries) { |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 314 | HashSet<PortStatistics> stats = Sets.newHashSet(); |
| 315 | |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 316 | for (OFPortStatsEntry entry : entries) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 317 | try { |
Thomas Vachuska | 4e6025e | 2015-06-03 11:25:21 -0700 | [diff] [blame] | 318 | if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) { |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 319 | continue; |
| 320 | } |
| 321 | DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder(); |
| 322 | DefaultPortStatistics stat = builder.setDeviceId(deviceId) |
| 323 | .setPort(entry.getPortNo().getPortNumber()) |
| 324 | .setPacketsReceived(entry.getRxPackets().getValue()) |
| 325 | .setPacketsSent(entry.getTxPackets().getValue()) |
| 326 | .setBytesReceived(entry.getRxBytes().getValue()) |
| 327 | .setBytesSent(entry.getTxBytes().getValue()) |
| 328 | .setPacketsRxDropped(entry.getRxDropped().getValue()) |
| 329 | .setPacketsTxDropped(entry.getTxDropped().getValue()) |
| 330 | .setPacketsRxErrors(entry.getRxErrors().getValue()) |
| 331 | .setPacketsTxErrors(entry.getTxErrors().getValue()) |
| 332 | .setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()) |
| 333 | .setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()) |
| 334 | .build(); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 335 | |
Thomas Vachuska | f0397b5 | 2015-05-29 13:50:17 -0700 | [diff] [blame] | 336 | stats.add(stat); |
| 337 | } catch (Exception e) { |
| 338 | LOG.warn("Unable to process port stats", e); |
| 339 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | return Collections.unmodifiableSet(stats); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener { |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 346 | |
Srikanth Vavilapalli | 78baf58 | 2015-06-05 11:40:14 -0700 | [diff] [blame] | 347 | private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>(); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 348 | private boolean isDisabled = false; |
Thomas Vachuska | 893bf4b | 2015-05-29 18:13:18 -0700 | [diff] [blame] | 349 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 350 | @Override |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 351 | public void switchAdded(Dpid dpid) { |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 352 | if (providerService == null) { |
| 353 | return; |
| 354 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 355 | DeviceId did = deviceId(uri(dpid)); |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 356 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 357 | if (sw == null) { |
| 358 | return; |
| 359 | } |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 360 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 361 | ChassisId cId = new ChassisId(dpid.value()); |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 362 | |
Thomas Vachuska | 82041f5 | 2014-11-30 22:14:02 -0800 | [diff] [blame] | 363 | SparseAnnotations annotations = DefaultAnnotations.builder() |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 364 | .set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString()) |
| 365 | .set(AnnotationKeys.CHANNEL_ID, sw.channelId()) |
| 366 | .set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0]) |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 367 | .build(); |
| 368 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 369 | DeviceDescription description = |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 370 | new DefaultDeviceDescription(did.uri(), sw.deviceType(), |
Ray Milkey | d3edd03 | 2015-01-16 11:38:58 -0800 | [diff] [blame] | 371 | sw.manufacturerDescription(), |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 372 | sw.hardwareDescription(), |
| 373 | sw.softwareDescription(), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 374 | sw.serialNumber(), |
Thomas Vachuska | 82041f5 | 2014-11-30 22:14:02 -0800 | [diff] [blame] | 375 | cId, annotations); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 376 | providerService.deviceConnected(did, description); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 377 | providerService.updatePorts(did, buildPortDescriptions(sw)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 378 | |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 379 | PortStatsCollector psc = new PortStatsCollector(sw, portStatsPollFrequency); |
| 380 | stopCollectorIfNeeded(collectors.put(dpid, psc)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 381 | psc.start(); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 382 | |
| 383 | //figure out race condition for collectors.remove() and collectors.put() |
| 384 | if (controller.getSwitch(dpid) == null) { |
| 385 | switchRemoved(dpid); |
| 386 | } |
alshabib | 25c8eec | 2014-09-04 16:41:31 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 389 | private void stopCollectorIfNeeded(PortStatsCollector collector) { |
| 390 | if (collector != null) { |
| 391 | collector.stop(); |
| 392 | } |
| 393 | } |
| 394 | |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 395 | @Override |
| 396 | public void switchRemoved(Dpid dpid) { |
alshabib | 6f5460b | 2014-09-03 14:46:17 -0700 | [diff] [blame] | 397 | if (providerService == null) { |
| 398 | return; |
| 399 | } |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 400 | providerService.deviceDisconnected(deviceId(uri(dpid))); |
Thomas Vachuska | a394b95 | 2016-06-14 15:02:09 -0700 | [diff] [blame] | 401 | stopCollectorIfNeeded(collectors.remove(dpid)); |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 402 | } |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 403 | |
| 404 | @Override |
| 405 | public void switchChanged(Dpid dpid) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 406 | LOG.debug("switchChanged({})", dpid); |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 407 | if (providerService == null) { |
| 408 | return; |
| 409 | } |
| 410 | DeviceId did = deviceId(uri(dpid)); |
| 411 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
Lei Xu | dee1aff | 2015-10-16 00:45:10 -0500 | [diff] [blame] | 412 | if (sw == null) { |
| 413 | return; |
| 414 | } |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 415 | final List<PortDescription> ports = buildPortDescriptions(sw); |
| 416 | LOG.debug("switchChanged({}) {}", did, ports); |
| 417 | providerService.updatePorts(did, ports); |
Ayaka Koshibe | 38594c2 | 2014-10-22 13:36:12 -0700 | [diff] [blame] | 418 | } |
| 419 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 420 | @Override |
| 421 | public void portChanged(Dpid dpid, OFPortStatus status) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 422 | LOG.debug("portChanged({},{})", dpid, status); |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 423 | PortDescription portDescription = buildPortDescription(status); |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 424 | providerService.portStatusChanged(deviceId(uri(dpid)), portDescription); |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 427 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 428 | public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 429 | LOG.debug("receivedRoleReply({},{},{})", dpid, requested, response); |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 430 | MastershipRole request = roleOf(requested); |
| 431 | MastershipRole reply = roleOf(response); |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 432 | providerService.receivedRoleReply(deviceId(uri(dpid)), request, reply); |
| 433 | } |
| 434 | |
| 435 | /** |
| 436 | * Translates a RoleState to the corresponding MastershipRole. |
| 437 | * |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 438 | * @param response role state |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 439 | * @return a MastershipRole |
| 440 | */ |
| 441 | private MastershipRole roleOf(RoleState response) { |
| 442 | switch (response) { |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 443 | case MASTER: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 444 | return MastershipRole.MASTER; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 445 | case EQUAL: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 446 | return MastershipRole.STANDBY; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 447 | case SLAVE: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 448 | return MastershipRole.NONE; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 449 | default: |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 450 | LOG.warn("unknown role {}", response); |
| 451 | return null; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 452 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 453 | } |
| 454 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 455 | /** |
| 456 | * Builds a list of port descriptions for a given list of ports. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 457 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 458 | * @return list of portdescriptions |
| 459 | */ |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 460 | private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) { |
| 461 | final List<PortDescription> portDescs = new ArrayList<>(sw.getPorts().size()); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 462 | if (!((Device.Type.ROADM.equals(sw.deviceType())) || |
| 463 | (Device.Type.OTN.equals(sw.deviceType())))) { |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 464 | sw.getPorts().forEach(port -> portDescs.add(buildPortDescription(port))); |
| 465 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 466 | |
| 467 | OpenFlowOpticalSwitch opsw; |
| 468 | switch (sw.deviceType()) { |
| 469 | case ROADM: |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 470 | case OTN: |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 471 | opsw = (OpenFlowOpticalSwitch) sw; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 472 | List<OFPortDesc> ports = opsw.getPorts(); |
| 473 | LOG.debug("SW ID {} , ETH- ODU CLT Ports {}", opsw.getId(), ports); |
| 474 | // ODU client ports are reported as ETH |
| 475 | ports.forEach(port -> portDescs.add(buildOduCltPortDescription(port))); |
| 476 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 477 | opsw.getPortTypes().forEach(type -> { |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 478 | List<? extends OFObject> portsOf = opsw.getPortsOf(type); |
| 479 | LOG.debug("Ports Of{}", portsOf); |
| 480 | portsOf.forEach( |
| 481 | op -> { |
HIGUCHI Yuta | 1979f55 | 2015-12-28 21:24:26 -0800 | [diff] [blame] | 482 | portDescs.add(buildPortDescription(type, op)); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 483 | } |
| 484 | ); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 485 | }); |
| 486 | break; |
| 487 | case FIBER_SWITCH: |
| 488 | opsw = (OpenFlowOpticalSwitch) sw; |
| 489 | opsw.getPortTypes().forEach(type -> { |
| 490 | opsw.getPortsOf(type).forEach( |
| 491 | op -> { |
| 492 | portDescs.add(buildPortDescription((OFCalientPortDescStatsEntry) op)); |
| 493 | } |
| 494 | ); |
| 495 | }); |
| 496 | break; |
| 497 | default: |
| 498 | break; |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 499 | } |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 500 | |
alshabib | 4680bb6 | 2014-09-04 17:15:08 -0700 | [diff] [blame] | 501 | return portDescs; |
| 502 | } |
| 503 | |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 504 | private PortDescription buildOduCltPortDescription(OFPortDesc port) { |
| 505 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 506 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && |
| 507 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 508 | Long portSpeedInMbps = portSpeed(port); |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 509 | CltSignalType sigType = null; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 510 | |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 511 | switch (portSpeedInMbps.toString()) { |
| 512 | case "1000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 513 | sigType = CltSignalType.CLT_1GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 514 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 515 | case "10000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 516 | sigType = CltSignalType.CLT_10GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 517 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 518 | case "40000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 519 | sigType = CltSignalType.CLT_40GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 520 | break; |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 521 | case "100000": |
Toru Furusawa | 72ee30c | 2016-01-08 13:29:04 -0800 | [diff] [blame] | 522 | sigType = CltSignalType.CLT_100GBE; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 523 | break; |
| 524 | default: |
Rimon Ashkenazy | d15ebf5 | 2016-01-06 14:36:13 +0200 | [diff] [blame] | 525 | throw new RuntimeException("Un recognize OduClt speed: " + portSpeedInMbps.toString()); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | SparseAnnotations annotations = buildOduCltAnnotation(port); |
HIGUCHI Yuta | 4c0ef6b | 2016-05-02 19:45:41 -0700 | [diff] [blame] | 529 | return oduCltPortDescription(portNo, enabled, sigType, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | private SparseAnnotations buildOduCltAnnotation(OFPortDesc port) { |
| 533 | SparseAnnotations annotations = null; |
| 534 | String portName = Strings.emptyToNull(port.getName()); |
| 535 | if (portName != null) { |
| 536 | annotations = DefaultAnnotations.builder() |
| 537 | .set(AnnotationKeys.PORT_NAME, portName) |
| 538 | .set(AnnotationKeys.STATIC_PORT, Boolean.TRUE.toString()).build(); |
| 539 | } |
| 540 | return annotations; |
| 541 | } |
| 542 | |
| 543 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port) { |
| 544 | if (port instanceof OFPortOptical) { |
| 545 | return buildPortDescription(ptype, (OFPortOptical) port); |
| 546 | } |
| 547 | return buildPortDescription(ptype, (OFExpPort) port); |
| 548 | } |
| 549 | |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 550 | private boolean matchingOtuPortSignalTypes(OFPortOpticalTransportSignalType sigType, |
| 551 | OduSignalType oduSignalType) { |
| 552 | switch (sigType) { |
| 553 | case OTU2: |
| 554 | if (oduSignalType == OduSignalType.ODU2) { |
| 555 | return true; |
| 556 | } |
| 557 | break; |
| 558 | case OTU4: |
| 559 | if (oduSignalType == OduSignalType.ODU4) { |
| 560 | return true; |
| 561 | } |
| 562 | break; |
| 563 | default: |
| 564 | break; |
| 565 | } |
| 566 | return false; |
| 567 | } |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 568 | /** |
| 569 | * Build a portDescription from a given a port description describing some |
| 570 | * Optical port. |
| 571 | * |
| 572 | * @param ptype description property type. |
| 573 | * @param port the port to build from. |
| 574 | * @return portDescription for the port. |
| 575 | */ |
| 576 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFExpPort port) { |
| 577 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 578 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 579 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 580 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 581 | |
| 582 | OFExpPortDescPropOpticalTransport firstProp = port.getProperties().get(0); |
| 583 | OFPortOpticalTransportSignalType sigType = firstProp.getPortSignalType(); |
| 584 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 585 | PortDescription portDes = null; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 586 | switch (sigType) { |
| 587 | case OMSN: |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 588 | portDes = omsPortDescription(portNo, enabled, |
Rimon Ashkenazy | e320103 | 2016-01-11 14:27:30 +0200 | [diff] [blame] | 589 | FREQ191_7, FREQ191_7.add(FREQ4_4), FREQ50, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 590 | break; |
| 591 | case OCH: |
| 592 | OFExpPortOpticalTransportLayerEntry entry = firstProp.getFeatures().get(0).getValue().get(0); |
| 593 | OFPortOpticalTransportLayerClass layerClass = entry.getLayerClass(); |
| 594 | if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) { |
| 595 | LOG.error("Unsupported layer Class {} ", layerClass); |
| 596 | return null; |
| 597 | } |
| 598 | |
| 599 | // convert to ONOS OduSignalType |
| 600 | OduSignalType oduSignalType = OpenFlowDeviceValueMapper. |
| 601 | lookupOduSignalType((byte) entry.getSignalType()); |
| 602 | //OchSignal is needed for OchPortDescription constructor, |
| 603 | //yet not relevant for tunable OCH port, creating with default parameters |
| 604 | OchSignal signalId = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 1, 1); |
| 605 | |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 606 | portDes = ochPortDescription(portNo, enabled, |
| 607 | oduSignalType, true, |
| 608 | signalId, annotations); |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 609 | |
| 610 | break; |
| 611 | case OTU2: |
| 612 | case OTU4: |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 613 | entry = firstProp.getFeatures().get(0).getValue().get(0); |
| 614 | layerClass = entry.getLayerClass(); |
| 615 | if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) { |
| 616 | LOG.error("Unsupported layer Class {} ", layerClass); |
| 617 | return null; |
| 618 | } |
| 619 | |
| 620 | // convert to ONOS OduSignalType |
| 621 | OduSignalType oduSignalTypeOtuPort = OpenFlowDeviceValueMapper. |
| 622 | lookupOduSignalType((byte) entry.getSignalType()); |
| 623 | if (!matchingOtuPortSignalTypes(sigType, oduSignalTypeOtuPort)) { |
| 624 | LOG.error("Wrong oduSignalType {} for OTU Port sigType {} ", oduSignalTypeOtuPort, sigType); |
| 625 | return null; |
| 626 | } |
| 627 | OtuSignalType otuSignalType = |
| 628 | ((sigType == OFPortOpticalTransportSignalType.OTU2) ? OtuSignalType.OTU2 : |
| 629 | OtuSignalType.OTU4); |
HIGUCHI Yuta | 5be3e82 | 2016-05-03 13:51:42 -0700 | [diff] [blame] | 630 | portDes = otuPortDescription(portNo, enabled, otuSignalType, annotations); |
Rimon Ashkenazy | 8ebfff0 | 2016-02-01 11:56:36 +0200 | [diff] [blame] | 631 | break; |
Yafit Hadar | a9a73de | 2015-09-06 13:52:52 +0300 | [diff] [blame] | 632 | default: |
| 633 | break; |
| 634 | } |
| 635 | |
| 636 | return portDes; |
| 637 | } |
| 638 | |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 639 | /** |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 640 | * Creates an annotation for the port name if one is available. |
| 641 | * |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 642 | * @param portName the port name |
| 643 | * @param portMac the port mac |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 644 | * @return annotation containing the port name if one is found, |
| 645 | * null otherwise |
| 646 | */ |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 647 | private SparseAnnotations makePortAnnotation(String portName, String portMac) { |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 648 | SparseAnnotations annotations = null; |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 649 | String pName = Strings.emptyToNull(portName); |
| 650 | String pMac = Strings.emptyToNull(portMac); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 651 | if (portName != null) { |
| 652 | annotations = DefaultAnnotations.builder() |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 653 | .set(AnnotationKeys.PORT_NAME, pName) |
| 654 | .set(AnnotationKeys.PORT_MAC, pMac).build(); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 655 | } |
| 656 | return annotations; |
| 657 | } |
| 658 | |
| 659 | /** |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 660 | * Build a portDescription from a given Ethernet port description. |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 661 | * |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 662 | * @param port the port to build from. |
| 663 | * @return portDescription for the port. |
| 664 | */ |
| 665 | private PortDescription buildPortDescription(OFPortDesc port) { |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 666 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 667 | boolean enabled = |
| 668 | !port.getState().contains(OFPortState.LINK_DOWN) && |
| 669 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
| 670 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 671 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 672 | return new DefaultPortDescription(portNo, enabled, type, |
| 673 | portSpeed(port), annotations); |
alshabib | a14f364 | 2014-09-05 09:31:31 -0700 | [diff] [blame] | 674 | } |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 675 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 676 | /** |
| 677 | * Build a portDescription from a given a port description describing some |
| 678 | * Optical port. |
| 679 | * |
| 680 | * @param port description property type. |
| 681 | * @param port the port to build from. |
| 682 | * @return portDescription for the port. |
| 683 | */ |
| 684 | private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port) { |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 685 | checkArgument(port.getDesc().size() >= 1); |
| 686 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 687 | // Minimally functional fixture. This needs to be fixed as we add better support. |
| 688 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 689 | |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 690 | boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) |
| 691 | && !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 692 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 693 | |
| 694 | if (port.getVersion() == OFVersion.OF_13 |
| 695 | && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) { |
| 696 | // At this point, not much is carried in the optical port message. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 697 | LOG.debug("Optical transport port message {}", port.toString()); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 698 | } else { |
| 699 | // removable once 1.4+ support complete. |
Ayaka Koshibe | ae54173 | 2015-05-19 13:37:27 -0700 | [diff] [blame] | 700 | LOG.debug("Unsupported optical port properties"); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 701 | } |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 702 | |
| 703 | OFPortDescPropOpticalTransport desc = port.getDesc().get(0); |
| 704 | switch (desc.getPortSignalType()) { |
| 705 | // FIXME: use constants once loxi has full optical extensions |
| 706 | case 2: // OMS port |
| 707 | // Assume complete optical spectrum and 50 GHz grid |
| 708 | // LINC-OE is only supported optical OF device for now |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 709 | return omsPortDescription(portNo, enabled, |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 710 | Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(50), annotations); |
| 711 | case 5: // OCH port |
| 712 | OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4); |
HIGUCHI Yuta | 34a3f69 | 2016-01-09 21:08:57 -0800 | [diff] [blame] | 713 | return ochPortDescription(portNo, enabled, OduSignalType.ODU4, |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 714 | true, signal, annotations); |
| 715 | default: |
| 716 | break; |
| 717 | } |
| 718 | |
Ayaka Koshibe | 74b5527 | 2015-05-28 15:16:04 -0700 | [diff] [blame] | 719 | return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations); |
Ayaka Koshibe | 5460d62 | 2015-05-14 12:19:19 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 722 | /** |
| 723 | * Build a portDescription from a given port description describing a fiber switch optical port. |
| 724 | * |
| 725 | * @param port description property type. |
| 726 | * @param port the port to build from. |
| 727 | * @return portDescription for the port. |
| 728 | */ |
| 729 | private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) { |
| 730 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 731 | |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 732 | // Use the alias name if it's available |
| 733 | String name = port.getName(); |
| 734 | List<OFCalientPortDescProp> props = port.getProperties(); |
| 735 | if (props != null && props.size() > 0) { |
| 736 | OFCalientPortDescPropOptical propOptical = (OFCalientPortDescPropOptical) props.get(0); |
| 737 | if (propOptical != null) { |
| 738 | name = propOptical.getInAlias(); |
| 739 | } |
| 740 | } |
| 741 | |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 742 | // FIXME when Calient OF agent reports port status |
| 743 | boolean enabled = true; |
Marc De Leenheer | c662d32 | 2016-02-18 16:05:10 -0800 | [diff] [blame] | 744 | SparseAnnotations annotations = makePortAnnotation(name, port.getHwAddr().toString()); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 745 | |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 746 | // S160 data sheet |
| 747 | // 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] | 748 | return omsPortDescription(portNo, enabled, |
Marc De Leenheer | fc913dd | 2015-07-30 16:04:55 -0700 | [diff] [blame] | 749 | Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(100), annotations); |
Marc De Leenheer | b931137 | 2015-07-09 11:36:49 -0700 | [diff] [blame] | 750 | } |
| 751 | |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 752 | private PortDescription buildPortDescription(OFPortStatus status) { |
| 753 | OFPortDesc port = status.getDesc(); |
| 754 | if (status.getReason() != OFPortReason.DELETE) { |
| 755 | return buildPortDescription(port); |
| 756 | } else { |
| 757 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
| 758 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 759 | SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); |
Ray Milkey | e0fade7 | 2015-01-15 13:29:47 -0800 | [diff] [blame] | 760 | return new DefaultPortDescription(portNo, false, type, |
| 761 | portSpeed(port), annotations); |
alshabib | afc514a | 2014-12-01 14:44:05 -0800 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 765 | private long portSpeed(OFPortDesc port) { |
| 766 | if (port.getVersion() == OFVersion.OF_13) { |
Charles Chan | 25b7732 | 2015-12-13 01:00:56 -0800 | [diff] [blame] | 767 | // Note: getCurrSpeed() returns a value in kbps (this also applies to OF_11 and OF_12) |
| 768 | return port.getCurrSpeed() / KBPS; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | PortSpeed portSpeed = PortSpeed.SPEED_NONE; |
| 772 | for (OFPortFeatures feat : port.getCurr()) { |
| 773 | portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed()); |
| 774 | } |
Thomas Vachuska | 98eda53 | 2014-10-29 17:31:02 -0700 | [diff] [blame] | 775 | return portSpeed.getSpeedBps() / MBPS; |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 776 | } |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 777 | |
| 778 | @Override |
| 779 | public void handleMessage(Dpid dpid, OFMessage msg) { |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 780 | if (isDisabled) { |
| 781 | return; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 782 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 783 | |
| 784 | try { |
| 785 | switch (msg.getType()) { |
| 786 | case STATS_REPLY: |
| 787 | if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { |
| 788 | OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; |
| 789 | List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); |
| 790 | if (portStatsReplyList == null) { |
Madan Jampani | 84382b9 | 2016-06-22 08:26:49 -0700 | [diff] [blame^] | 791 | portStatsReplyList = Lists.newCopyOnWriteArrayList(); |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 792 | } |
| 793 | portStatsReplyList.addAll(portStatsReply.getEntries()); |
| 794 | portStatsReplies.put(dpid, portStatsReplyList); |
| 795 | if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
Charles Chan | b3ef0db | 2016-05-03 11:11:00 -0700 | [diff] [blame] | 796 | List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid); |
| 797 | if (statsEntries != null) { |
| 798 | pushPortMetrics(dpid, statsEntries); |
| 799 | statsEntries.clear(); |
| 800 | } |
Ray Milkey | 7abe50b | 2016-04-13 11:57:44 -0700 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | break; |
| 804 | case ERROR: |
| 805 | if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) { |
| 806 | LOG.error("port mod failed"); |
| 807 | } |
| 808 | default: |
| 809 | break; |
| 810 | } |
| 811 | } catch (IllegalStateException e) { |
| 812 | // system is shutting down and the providerService is no longer |
| 813 | // valid. Messages cannot be processed. |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | private void disable() { |
| 818 | isDisabled = true; |
sangho | 538108b | 2015-04-08 14:29:20 -0700 | [diff] [blame] | 819 | } |
alshabib | f1216ed | 2014-09-03 11:53:54 -0700 | [diff] [blame] | 820 | } |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame] | 821 | |
| 822 | |
tom | b5a46e6 | 2014-08-26 14:20:00 -0700 | [diff] [blame] | 823 | } |