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